ILoggingBuilder AddEventLog Linux 兼容性

问题描述 投票:0回答:2

当应用程序在 Linux 操作系统下运行时,

AddEventLog
的扩展方法
Microsoft.Extensions.Logging.ILoggingBuilder
是否也有效?或者当没有 Windows 事件日志时会导致异常吗?

.net asp.net-core logging event-log
2个回答
1
投票

不,不是。事件日志是特定于 Windows 的,事实上,如果您在没有明确检查 Windows 支持的情况下尝试使用它,您将在 IDE 中收到警告:

Image of visual studio showing the AddEventLog call with an analyzer warning because of the code is windows specific


0
投票

要消除警告,您可以将其包装在操作系统检查中,如下所示

  if (OperatingSystem.IsWindows()) {
      builder.Logging.AddEventLog();     
  }
© www.soinside.com 2019 - 2024. All rights reserved.