Return-Path: Delivered-To: apmail-logging-log4net-user-archive@www.apache.org Received: (qmail 2438 invoked from network); 26 Sep 2005 05:16:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 26 Sep 2005 05:16:06 -0000 Received: (qmail 82239 invoked by uid 500); 26 Sep 2005 05:16:05 -0000 Delivered-To: apmail-logging-log4net-user-archive@logging.apache.org Received: (qmail 82200 invoked by uid 500); 26 Sep 2005 05:16:04 -0000 Mailing-List: contact log4net-user-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Log4NET User" List-Id: Delivered-To: mailing list log4net-user@logging.apache.org Received: (qmail 82187 invoked by uid 99); 26 Sep 2005 05:16:04 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 25 Sep 2005 22:16:04 -0700 X-ASF-Spam-Status: No, hits=0.4 required=10.0 tests=DNS_FROM_RFC_ABUSE X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [68.142.207.138] (HELO web32207.mail.mud.yahoo.com) (68.142.207.138) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 25 Sep 2005 22:16:10 -0700 Received: (qmail 91974 invoked by uid 60001); 26 Sep 2005 05:15:41 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=2X+KDEKta2hrlTV30S3mh1eceDAT7/lNv5Mk0Q6GF4fQDJL6Ca65Hz3yiqyTnv8lCWtdkXawR1Auovhnl/cCcGzmxi6wu0gBTtGBjxGNraCgOZ+Crp+8WMXouWv1yZELp/t11wziaoX9Qoe52MooxX5kir0Lu4GpMisOEl/J+9c= ; Message-ID: <20050926051541.91972.qmail@web32207.mail.mud.yahoo.com> Received: from [65.24.255.41] by web32207.mail.mud.yahoo.com via HTTP; Sun, 25 Sep 2005 22:15:41 PDT Date: Sun, 25 Sep 2005 22:15:41 -0700 (PDT) From: Ron Grabowski Subject: RE: How to log EventID with EventLogAppender? To: Log4NET User In-Reply-To: <20050925235235.3CFAC10FB2B0@asf.osuosl.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --- Billy Barnum wrote: > Right. Log4Net error msgs all have the same eventId. This is exactly > what I > want to change. The documentation for the EventLogAppender says: " If the event has an EventID property set then this integer will be used as the event log event id. " which means if you set an EventID property: log4net.ThreadContext.Properties["EventID"] = 5; That value will be sent to the Event Log. I may have used incorrect casing on EventID in one of my earlier posts. > I'm certainly no EventLog guru, but what I know is this: EventId is > not a PK > at all. It is, however, meant to be unique within an EventSource and > optionally an EventCategory; usage is up to the application. The idea > is > EventSource and EventCategory provide context, while EventId > identfies the > particular problem. 2 side notes: The EventSource property for an event log entry is set via the EventLogAppender's ApplicatioName property. The default value is: System.Threading.Thread.GetDomain().FriendlyName I don't think this is a value that needs to be settable on a per message basis. > 1. Log4Net already provides built-in context with the logger property > that > you can put in your logging message. IMHO it would be a great log4net > enhancement if this was passed through to the EventCategory field in > the > EventLog for EventLogAppender in addition to or instead of putting it > in the There's currently no way to pass in or set an Event Category value for an event log entry. EventLogAppender uses this overload when logging which doesn't pass in a value for event category: EventLog.WriteEntry(string, string, EventLogEntryType, int) I agree that it would be nice if it were possible to specify an Event Category for each message logged or a default value for Event Category. Since we're already looking for EventID in the logging event's properties we may want to also look for EventCategory and use that value to call this overload: EventLog.WriteEntry(string, string, EventLogEntryType, int, short) Do you think it would be useful to allow default values for these properties to be specified inside the config file and used if the EventID or EventCategory property keys aren't present? > msg. If I get some time here I'll dig in and do it myself. I haven't > actually built log4net yet; I've only been using the executable > having just > been using log4net for a week. If you're going to use TortoiseCVS to checkout the files this post may be helpful: http://www.mail-archive.com/log4net-user@logging.apache.org/msg02060.html Apache is going to be moving everything to SVN before the end of year. I thought the Logging Servics projects had a date set a few weeks ago to make their move. I don't think has happened yet. > Back to issue at hand ... Ron, I tried your example code there, with > the > threadcontext/setting EventId property to 5, and all. Quick questions > if you > have time ... no hurry ... I must not have read the documentation correctly...try EventID. > 1. What's the diff between this threadcontext and MDC/NDC? This is what the release notes have to say about it: http://logging.apache.org/log4net/release/release-notes.html#1.2.9-new MDC is now implemented using the ThreadContext. > 2. I still don't see how that eventid 5 gets to the eventid field in > EventLogAppender without going the extension route (your 2nd > example). What > do you put in your xml file? How does that go anywhere other than the > message text? log4net.ThreadContext.Properties["EventID"] = 5; log.Debug("Hello World"); I don't think writting your own ILog is as terrible an idea as people sometimes think it is. Log4net as we know it is really ILogger. The default implementation of ILogger is itself abstracted through the ILog interface. If you know your company or project is going to be logging a lot of additional information other than the just messages and exceptions, I would write a LogManager that returns a custom ILog: Company.Project.Logging.ILog You could write your implementation in such a way that you can load up either log4net 1.2.0 beta 8, log4net 1.2.9 beta, NLog, or MS's Logging Block at runtime without having to reference those assemblies directly from your project. > 3. When I used that threadcontext code, asp rebooted itself with err > msgs - > which is sometimes a sign of stack overflow. Was there some cleanup > and/or > stack popping I needed to do? Posting the code you used and the error messages generated is always helpful :)