0

I try to write new log to MyLog but it always writes to Application Log (Windows Log)

 string sSource;
 string sLog;
 sSource = "MySource";
 sLog = "MyLog";
 if (!EventLog.SourceExists(sSource))
     EventLog.CreateEventSource(sSource, sLog);
 using (EventLog eventLog = new EventLog(sLog))
 {
     eventLog.Source = sSource;
     eventLog.WriteEntry("Log message example", EventLogEntryType.Information, 101, 1);
 }

I tried to delete the log entry on Registry to recreate the log but the problem still persists.

Ty any help.

Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
nam vo
  • 3,271
  • 12
  • 49
  • 76

1 Answers1

0

I use nearly the same code, with two differences. I set the log manually not in the constructor and I don't give a category on the WriteEntry method:

    string sSource;
    string sLog;
    sSource = "MySource";
    sLog = "MyLog";
    if (!EventLog.SourceExists(sSource))
        EventLog.CreateEventSource(sSource, sLog);
    using (EventLog eventLog = new EventLog())
    {
        eventLog.Source = sSource;
        eventLog.Log = sLog;
        eventLog.WriteEntry("Log message example", EventLogEntryType.Information, 101);
    }
Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55