Search code examples
c#eventlog-source

.NET Runtime does not show up in LogNames


Does anyone have an idea why the '.NET Runtime' Event source does not behave like a normal event source?

var logCheckOne = EventLog.Exists(".NET Runtime");

var logCheckTwo = EventLogSession
                    .GlobalSession
                    .GetLogNames()
                    .Any(s => string.Equals(s, ".NET Runtime", StringComparison.OrdinalIgnoreCase));

Both of these lines of code return false and yet in Event Viewer, there is clearly a ".NET Runtime" event source AND I can write to it without issue.

Why is this broken? Is there a way to get a 'true' list of Event Sources?


Solution

  • The 'LogName' is 'Application', the 'Source Name' is '.NET Runtime', so it seems you are not querying correctly.

    try:

    var logCheckOne = EventLog.SourceExists(".NET Runtime")