3

In a Onion Architecture context, how would I implement NLog in Asp.Net Core? I suppose I'll have to create a separate project with the scope to wrapping and mapping NLog to native .dotnet Core Logger (Microsoft.Extensions.Logging.ILogger) and then add this dependency to web project and in case in other project (services, other infrastructures...), right?

Thank you so much.

Dallas
  • 494
  • 3
  • 14
  • 2
    This may sound strange but I'd just use the built-in .NET TraceWriter for logging and use [the NLog TraceListener for routing output as you like.](http://nlog-project.org/2010/09/02/routing-system-diagnostics-trace-and-system-diagnostics-tracesource-logs-through-nlog.html) You get nice clean logging code without all the DI ceremony and domain model 'stress'. – Sixto Saez Mar 20 '18 at 15:24
  • Duplicate of https://stackoverflow.com/questions/39031585/how-do-i-log-from-other-classes-than-the-controller-in-asp-net-core ? – Rolf Kristensen Mar 20 '18 at 18:31

1 Answers1

2

This is my solution

The asp.net core project has no references to NLog.

Project NLogNet in the repo implements the standard solution

All other projects implements the solution with a structure based on Onion Architecture

Dallas
  • 494
  • 3
  • 14