How do you log to the Windows event log from C# .NET?

This seems to do the trick if you want to log to the Windows event log:

private void logError(string message, string source)
	System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
	log.Source = source;
	log.WriteEntry(message, System.Diagnostics.EventLogEntryType.Error);

private void logError(Exception exception, string source)
	logError(exception.ToString(), source);

Put it in your class, or in a special logging class.

Read more:

Internt/Egna SharePoint – Miniprojekt Utveckling/Design Lookup fält programmagiskt… / ContentTypes

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.