Monthly Archives: May 2011

A simple class for EventLog writing in C# .NET

A simple class with a method for creating your own entries to the operating system’s event log by using the Microsoft .NET Framework. More info http://support.microsoft.com/kb/307024.

using System;
using System.Text;
using System.Diagnostics;

namespace Logs //your namespace here
{
    public class OSEventLog
    {
        public static void Write(string message, EventLogEntryType type)
        {
            string source = “SYSteam.NCA.CRM.Mesh.Import”;
            string log = “Application”;
           
            if (!EventLog.SourceExists(source))
                EventLog.CreateEventSource(source,log);
                       
            EventLog.WriteEntry(source, message, type);
        }
    }
}