异常信息:System.PlatformNotSupportedException:此平台不支持事件日志访问

coc*_*o18 16 c# windows-services .net-core

当我尝试在目标计算机(Windows 服务器)上启动工作服务时,出现上述错误。我尝试了一切,但没有成功。我仍然收到错误。我正在使用 .NET Core 3.1 和 Microsoft.Extensions.Logging 7.0.0。这是导致问题的代码:

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

Run Code Online (Sandbox Code Playgroud)

一些有用的链接,我已经尝试过了:

链接1 链接2 链接3

如果有人能够帮助我,我将不胜感激。

更新:我正在使用 Microsoft.Extensions.Hosting 7.0.0 和 System.Diagnostics.EventLog 7.0.0。如果我将软件包降级到 6.0.0,它就可以工作。

coc*_*o18 29

将 Microsoft.Extensions.Hosting 7.0.0 和 System.Diagnostics.EventLog 7.0.0 降级到 6.0.0 似乎可以消除该问题

  • 对我来说,“Microsoft.Windows.Compatibility”与“7.0.0”抛出了这个错误。降级到“6.0.0”对我有用:) (3认同)