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);
	log.Close();
}

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s