Wednesday, September 9, 2009

How to Create Event Log Entry Using C#

public static void CreateEventlogEntry(EventLogSource eventLogSource, string message)

        {

            EventLog eventLog = new EventLog();

 

            try

            {

                string eventLogName = eventLogSource.ToString();

                try

                {

                    if (!EventLog.SourceExists(eventLogName))

                    {

                        EventLog.CreateEventSource(eventLogName, "Application");

                    }

                }

                catch { }

 

                eventLog.Source = eventLogName;

 

                eventLog.WriteEntry(message, EventLogEntryType.Error);

            }

            catch { }

 

        }

No comments: