Containers - Writing to Windows Event log from Containers throwing error "Inaccessible logs"

45 Views Asked by At

I am running a .net core (6.1) console application in containers. When it tries to write to the Windows Event log, it throws this error

The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security, State.

Here is the code:

string name = "My Console App";
try
{
    if (!EventLog.SourceExists(name))
    {
        EventLog.CreateEventSource(name, "Application");
    }

    EventLog.WriteEntry(name, pMessage, pEvntType);
}
catch (SecurityException ex)
{
    Console.WriteLine(ex.Message);
}

I have looked at a similar issues but they are all talking about IIS. Any help

0

There are 0 best solutions below