3

I'm implementing NLog with .NET Core 2 according to https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2 that uses these 2 packages:

  • NLog 4.5.0-rc03
  • NLog.Web.AspNetCore 4.5.0-rc2

The logging works fine, but now that I want to add Event Properties, the Log() function does not accept LogEventInfo as an argument.

Any thoughts would be helpful. Thanks in advance.

Kes
  • 448
  • 6
  • 20

1 Answers1

1

When using ASP.NET Core, you have two options to use NLog.

You could use Microsoft.Extensions.Logging (MEL), the logging abstraction is introduced by Microsoft. Then you can't use NLog types, like the LogEventInfo as the logging abstraction doesn't know NLog. For this you need the package NLog.Web.AspNetCore. See setup: Use NLog in ASP.NET Core application

Another option is to use NLog direct, so with the LogManager from NLog. Then you could use LogEventInfo.

See also Microsoft.Extensions.Logging Vs. NLog

You could also add custom LogEvent-properties using MEL-ILoggerProvider (without using NLog LogEventInfo directly):

https://github.com/NLog/NLog.Extensions.Logging/wiki/NLog-properties-with-Microsoft-Extension-Logging

Julian
  • 33,915
  • 22
  • 119
  • 174