Create event source and write an event to the event log : EventLog : Windows C# Examples


C# Examples » Windows » EventLog »

 

Create event source and write an event to the event log









    
using  System;
using  System.Diagnostics;

class  MainClass
{
        public  static  void  Main  ()  
        {
                if  (!EventLog.SourceExists("MyEventSource"))  
                {
                        EventLog.CreateEventSource("MyEventSource",  "Application");
                }

                //  Write  an  event  to  the  event  log.
                EventLog.WriteEntry(
                        "MyEventSource",                              //  Registered  event  source
                        "A  simple  test  event.",                //  Event  entry  message
                        EventLogEntryType.Information,  //  Event  type
                        1,                                                          //  Application  specific  ID
                        0,                                                          //  Application  specific  category
                        new  byte[]  {10,  55,  200}              //  Event  data
                );

        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Windows
» EventLog