EventLogAppender and log4net
Hey there,
I was looking into configuring Windows event logging for an ASP.NET Core application (running on
net8.0
) with log4net
. In brief, my log4net.config
configuration looks something like this:
I am using DI, so somewhere in my startup code I hook up log4net with options.AddLog4Net("log4net.config");
. This works fine with everything except the Windows event logger. I registered a new source via PowerShell prior to running the application with:
Also tried variants of this (-LogName Application
, etc.) to no avail. An older SO answer suggest that this is not working for .NET applications anymore (so only .NET Framework and .NET Standard compatible versions), see also:
https://stackoverflow.com/questions/61639853/c-sharp-windows-event-viewer
I looked at the source code here to confirm that:
https://github.com/apache/logging-log4net/blob/master/src/log4net/log4net.csproj#L22C23-L22C44
The project is targeting .NET Framework 4.62 and .NET Standard 2.0. So my takeaway is, that .NET (Core) does not support Windows Event Logs?Stack Overflow
C# windows event viewer
I want to log the errors from my C# app in Windows Event Viewer using log4net with the EventLogAppender (the errors must be logged under the Application log)
I have a log4net.config class with this...
GitHub
logging-log4net/src/log4net/log4net.csproj at master · apache/loggi...
Apache Log4net is a versatile, feature-rich, efficient logging API and backend for .NET - apache/logging-log4net
2 Replies
Note: I realize that the Windows Event Log only is supported on Windows, but I was working under the impression that the library was smart enough to figure that out on its own?
Ah, looking at this table:
https://logging.apache.org/log4net/release/framework-support.html
I can see that .NET 8 support is provided by .NET Standard 2.0, which means
EventLogAppender
is not supported unless I switch to .NET FrameowkrIf you're building a .NET 8 application, there is no reason at all to be using log4net, since it has a built in DI based logging framework.