Log Event in Windows Operating System Using C#

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");
            Console.Read();
        }

        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);

        }
    }

Posted

in

by

Tags:


Related Posts

Comments

Leave a Reply

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

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading