logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Billy Barnum" <b.bar...@comcast.net>
Subject RE: How to log EventID with EventLogAppender?
Date Sun, 25 Sep 2005 23:50:42 GMT
Right. Log4Net error msgs all have the same eventId. This is exactly what I
want to change.

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:

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
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.

2. There is a very helpful site out there http://www.eventid.net/ that
allows searching by eventsource, eventcategory, eventid. You get to see what
others have posted as solutions when they've had nasty things show up in
their EventLog. Some of it is free, and there's premium, paid info as well.
It's saved my butt a few times and is a great addition to general debugging
toolboxes.

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 ...

1. What's the diff between this threadcontext and MDC/NDC?
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?
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?

-B

WILLIAM BARNUM
14076 Rosario Rd.
Anacortes, WA 98221-8559
Phone: 360.299.3830 Cell: 360.202.3670
b.barnum@comcast.net
 

-----Original Message-----
From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Sent: Friday, September 23, 2005 2:27 PM
To: Log4NET User
Subject: RE: How to log EventID with EventLogAppender?

I'm not very familiar with the Event Log so bear with me...

I looked at some entries in the Event Log on my computer and saw that
for similiar messages, the Event ID was always the same. I thought the
Event ID was similiar to a primary key in a database. In other words I
thought that I could somehow query the Event Loger for a particular
event based on its Event ID:

 // WRONG ???
 EventLogEntry eventLogEntry = eventLog.GetEvent(eventId);

but it looks like that's not the case.

Are you wanting to set a default Event ID for your application?

<appender name="EventLogAppender"
type="log4net.Appender.EventLogAppender" >
<layout type="log4net.Layout.SimpleLayout" />
<eventId value="5" />
</appender>

Or setup default Event IDs in such a way that each log4net Level has
its own default EventId?

<appender name="InfoEventLogAppender"
type="log4net.Appender.EventLogAppender" >
<layout type="log4net.Layout.SimpleLayout" />
<eventId value="10" />
...
</appender>

<appender name="WarnEventLogAppender"
type="log4net.Appender.EventLogAppender" >
<layout type="log4net.Layout.SimpleLayout" />
<eventId value="100" />
...
</appender>

<appender name="ErrorEventLogAppender"
type="log4net.Appender.EventLogAppender" >
<layout type="log4net.Layout.SimpleLayout" />
<eventId value="1000" />
...
</appender>


Mime
View raw message