5

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

1

4 Answers 4

8

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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>

1 Comment

Syntax is: EventLog.CreateEventSource("programname_must_be_unique","new_Logname")
1

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

Comments

0

Here is an example of a custom Event logger for .Net 3.5 and 4.0.

Log4Net is also a great tool for this, in my case I was building a lib and the client's calling program did not have log4net..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.