Search code examples
c#.net-corewindows-services

Exception Info: System.PlatformNotSupportedException: EventLog access is not supported on this platform


I am getting the above mentioned error, when I tried to start the worker service on the target machine (windows server). I tried everything, but without any success. I am still getting the error. I'm using .NET Core 3.1 and Microsoft.Extensions.Logging 7.0.0. Here is the code, which causing the problem:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureLogging(x =>
                {
                    x.ClearProviders();
                    x.AddConsole();
                })
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddHostedService<Worker>();
                })
                .UseWindowsService();

Hier some helpful links, which I have allready tried:

Link1 Link2 Link3

I will be greatful, if someone will be able to help me.

UPDATE: I'm using Microsoft.Extensions.Hosting 7.0.0 and System.Diagnostics.EventLog 7.0.0. If I downgrade the packages to 6.0.0, it works.


Solution

  • Downgrading Microsoft.Extensions.Hosting 7.0.0 and System.Diagnostics.EventLog 7.0.0 to 6.0.0 seems to eliminate the problem