0

Does the extension method AddEventLog of Microsoft.Extensions.Logging.ILoggingBuilder does also work when the application runs under a Linux OS or would it cause an exception when there is no Windows Event Log present?

2 Answers 2

1

No it does not. The event log is windows specific and in fact, if you do try to use it without checking for windows support explicitly, you will get a warning in the IDE:

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

Sign up to request clarification or add additional context in comments.

1 Comment

In VSCode I do not get any warning. Not even via dotnet build.
0

To verify you can wrap it in a OS check like so

  if (OperatingSystem.IsWindows()) {
      builder.Logging.AddEventLog();     
  }

Even if the answer was yes/no today, there is no way to know what the future holds, so always check yourself to be safe. This also removes the warning that was mentioned.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.