so as per the MS documentation we can add EvventLog as one of the logging provider. However when i add Microsoft.Extensions.Logging.EventLog
package in my .NET Core 2 Web Api application i see yellow explaination mark like below
With such warning i was still able to add EventLog in BuildWebHost method
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseApplicationInsights()
.UseUrls("http://*:40006")
.ConfigureLogging((hostingContext,logging)=>
{
logging.AddEventLog(new Microsoft.Extensions.Logging.EventLog.EventLogSettings()
{
SourceName = "MySource",
});
})
.Build();
however when i run the application i get error
Could not load type 'System.Diagnostics.EventLog' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
and Warning
Severity Code Description Project File Line Suppression State Warning NU1701 Package 'Microsoft.Extensions.Logging.EventLog 2.0.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
If using 2.0 you'll need to add a reference to package
Microsoft.Windows.Compatibility
as described in ASP.NET Core and Windows Event Log.