ASP.NET Core and Windows Event Log

Ashkan Nourzadeh
1 min readJan 25, 2018

--

Background
As part of porting some WEB APIs to ASP.NET Core I needed to keep logging errors to EventLog.
Previously I published how to do this in ASP.NET WEB API, now I’m going to do the same thing but in ASP.NET Core.

According to docs, It’s easy as adding a reference to package Microsoft.Extensions.Logging.EventLog and calling AddEventLog() extension inside ConfigureLogging configure method.

But why this post exists then?
Because Microsoft.Extensions.Logging.EventLog depends on .NETFramework 4.6.1…

If you are targeting net461 or above, then you are OK. But if you are targeting netcoreapp2.0 then you need to Add a reference to package Microsoft.Windows.Compatibility so you won’t get the exception below.

Application startup exception: System.TypeLoadException: Could not load type 'System.Diagnostics.EventLog' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

--

--