Warm tip: This article is reproduced from serverfault.com, please click

Custom Event Log not showing

发布于 2020-07-29 11:56:20

Goal:

To create my own custom log under Applications and Services Logs under the Event Viewer:

Code snippet:

.Net CORE 3.1

Host.CreateDefaultBuilder(args)
            .ConfigureLogging((hostContext, logging) =>
            {
              logging.ClearProviders();
              logging.AddConfiguration(hostContext.Configuration.GetSection("Logging"));
              logging.AddEventLog(
               eventLogSettings =>
                {
                  eventLogSettings.LogName = "My Log";
                  eventLogSettings.SourceName = "Dummy";
                });
              logging.AddConsole();
            });
// somewhere in my code, I use ILogger to write to the log

Configuration

    "Logging": {
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Grpc": "Information",
        "Microsoft": "Information"
     }
   }

Problem:

While testin my developer machine, I see the log entry on the console, but I don't see the log in the Event Viewer. If I dropped the LogName, the log shows up in the Application Log on the Event Viewer. What am I missing?

Thanks!

Questioner
Johnny Wu
Viewed
0
Johnny Wu 2020-07-29 21:35:51

I picked up this in the Application Log:

The description for Event ID 0 from source Application cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer. If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event: Unable to log .NET application events. The source was not found, but some or all event logs could not be searched. To create the source, you need permission to read all event logs to make sure that the new source name is unique. Inaccessible logs: Security. the message resource is present but the message is not found in the string/message table

Resolution:

Close the VS and re-open it "as Administrator"