c# writing to the event viewer

后端 未结 3 1923
时光取名叫无心
时光取名叫无心 2020-12-23 15:57

I\'m trying to write to the event viewer in my c# code, but I\'m getting the wonderful \"Object reference not set to an instance of an object\" message. I\'d appreciate som

3条回答
  •  北海茫月
    2020-12-23 16:49

       private void WriteEventLogToFile()
        {
            try
            {
                using (EventLog eventLog = new EventLog("Application"))
                {
                 // source for your event 
                    eventLog.Source = "IAStorDataMgrSvc";
    
                 // Syntax details
                // eventLog.WriteEntry("details",type of event,event id);
                 eventLog.WriteEntry("Hard disk Failure details", EventLogEntryType.Information, 11);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    

提交回复
热议问题