When I use the following code to write to the application event log, everything works fine:
EventLog log = new EventLog(); log.Source = "Application"; log.WriteEntry("test message", EventLogEntryType.Error);
When I use code from MSDN and all other blogs, I get a security error (I assume because CreateEventSource raises it).
string sSource = "MyWebService"; string sLog = "myApplication"; string sMsg = errorMessage; if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog); EventLog.WriteEntry(sSource, sMsg, EventLogEntryType.Error);
So, I need to check if the source exists, if all I need is to write to the application log, which is by default?
What is the correct way to record in EventViewer?
c # event-log event-viewer
sarsnake
source share