Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a custom event log

Tags:

c#

How do I programmatically check for/create a custom event log to be viewed in Windows XP/2003 event viewer?

Right now I can create entries in the 'Application' log but want to have custom logs for my various applications.

I am using C# - .NET Framework 3.5

like image 457
John M Avatar asked Sep 01 '09 18:09

John M


3 Answers

The System.Diagnostics.EventLog class in the framework has a CreateEventSource method...

 EventLog.CreateEventSource(source, logName);

Be aware that to create a new eventLog (or eventLog Source) requires a higher level of authority (WIndows Access Control List (ACL) permissions), than does simply writing to the log, and normally, this access level is not available to most applications... So you will need to make sure your deployment process or deployment msi does the event log/source creation at that time... when the process installing the app should have sufficient permissions.

like image 141
Charles Bretana Avatar answered Nov 15 '22 13:11

Charles Bretana


You need to create a custom event log, as described here. If you are using log4net for logging (recommended), you can configure an EventLogAppender as in the following example:

<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
    <applicationName value="MyApp" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %-5level %logger - %message%newline" />
    </layout>
</appender>
like image 40
Vinay Sajip Avatar answered Nov 15 '22 14:11

Vinay Sajip


You need to specify the Log property of the EventLog object.

Documentation can be found here:

http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.log.aspx

like image 1
David Avatar answered Nov 15 '22 12:11

David