Log Event in Windows Operating System Using C#

Author posted by Jitendra on Posted on under category Categories c# and tagged as Tags with Leave a comment on Log Event in Windows Operating System Using C#

Tutorial on Logging Message in EventLog of Microsoft Windows.

Below is the Utility function used to log the message in Microsoft Windows Operating Systems.

class Program
        static void Main(string[] args)
            LogMessage("ShivaSoftBlog - Error Message", EventLogEntryType.Error);
            LogMessage("ShivaSoftBlog - Failure Audit Message", EventLogEntryType.FailureAudit);
            LogMessage("ShivaSoftBlog - Information Message", EventLogEntryType.Information);
            LogMessage("ShivaSoftBlog - Success Audit Message", EventLogEntryType.SuccessAudit);
            LogMessage("ShivaSoftBlog - Warning Message", EventLogEntryType.Warning);
            Console.WriteLine("LOg Success");

        private static void LogMessage(string message, EventLogEntryType logType)
            if (!EventLog.SourceExists("ShivaSoftBlog"))
                EventLog.CreateEventSource("ShivaSoftBlog", "Application");

            EventLog ncsLog = new EventLog();
            ncsLog.Source = "ShivaSoftBlog";
            ncsLog.WriteEntry(message, logType);


Related posts

Leave a Reply

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