Reputation: 45
How am i supposed to Log to the Windows EventViewer in a WinUI3 App? I was not able to find a working example.
Current Situation:
In every .NET Framework app i used System.Diagnostics.EventLog
to write more or less useful eventLog.WriteEntry(e.Message, EventLogEntryType.Error);
Messages into the 'Application' Log. The WiX Installer takes care of the EventSource creation during the App installation. Now, i tried to do the same with a WINUI3 App. The logging itself is working as expected. However the eventsource creation is not. I was not able to find any information on how to tell visualstudio to create an eventsource during installation, nor am i confident that this is the right way to go.
So, how am i supposed to do logging on winui if i do not want to log to seperate files wehre i do need seperate programs to read them.
I have had a look at the LoggingSession and LoggingChannel solution with samples. But i do not think this kind of log is consumable without extra tools that needs to be downloaded/installed.
Upvotes: 0
Views: 515
Reputation: 13666
Install the Microsoft.Extensions.Logging NuGet package and use it like this:
Microsoft.Extensions.Logging.EventLog.EventLogLoggerProvider eventLogLoggerProvider = new();
Microsoft.Extensions.Logging.ILogger logger = eventLogLoggerProvider.CreateLogger("EventLogExample");
logger.LogInformation("This is an information message");
Upvotes: 0