You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by sc...@consultant.com on 2010/08/17 11:08:22 UTC

Writing to the event


Hi,

 I'm wondering can you help me please? I want to use log4net to write error logs to the application event viewer. Specifically what I want to do is to send down an error mesage and event number inside the body of the log method. The event number should appear under the "event" column in the event viewer and the error in the "Description" field of the Event Properties.

something like:

log.Error(1234, someErrorInfo)
or 
log.Info(1234, someErrorInfo)

where the 1234 will appear in the "Event" column etc...

 Problem is though I'm not sure how to do it. I know that I need something beginning 
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">

inside the .config but that's a far as I get. I would appreciate some help guidance code-samples perhaps in this regard.

Cheers,
S.





Re: Writing to the event

Posted by Dean Fiala <df...@gmail.com>.
check out http://logging.apache.org/log4net/release/config-examples.html
and
http://logging.apache.org/log4net/release/faq.html#trouble-EventLog

for the basics of configuring logging to the event log and some issues
trying to do it from and ASP.NET application.

The syntax you are proposing to use is a little dubious, but if you
just make a standard call to the logger, the message will get passed
properly.

Passing the eventID requires the use of a property, and there is an
extended discussion here...

http://www.l4ndash.com/Log4NetMailArchive%2Ftabid%2F70%2Fforumid%2F1%2Fpostid%2F14282%2Fview%2Ftopic%2FDefault.aspx

and there is also an extension project that does this for you, though
you may have to rev it to the latest .NET version.

http://logging.apache.org/log4net/release/example-apps.html




On Tue, Aug 17, 2010 at 5:08 AM,  <sc...@consultant.com> wrote:
> Hi,
>  I'm wondering can you help me please? I want to use log4net to write error
> logs to the application event viewer. Specifically what I want to do is to
> send down an error mesage and event number inside the body of the log
> method. The event number should appear under the "event" column in the event
> viewer and the error in the "Description" field of the Event Properties.
> something like:
> log.Error(1234, someErrorInfo)
> or
> log.Info(1234, someErrorInfo)
>
> where the 1234 will appear in the "Event" column etc...
>  Problem is though I'm not sure how to do it. I know that I need something
> beginning
> <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
> inside the .config but that's a far as I get. I would appreciate some help
> guidance code-samples perhaps in this regard.
>
> Cheers,
> S.
>
>



-- 
Dean Fiala

RockNUG Figurehead
http://www.rocknug.org