Simple Injector: Register ILogger by using ILoggerFactory.CreateLogger()

Use the following registrations: container.RegisterInstance<ILoggerFactory>(loggerFactory); container.RegisterSingleton(typeof(ILogger<>), typeof(Logger<>)); Or, in case you are integrating Simple Injector into a generic host or ASP.NET Core application, make use of the .AddLogging() extension method to even inject a non-generic ILogger into your application components, as demonstrates in this ASP.NET Core Startup class: public class Startup { … public void … Read more

Microsoft.Extensions.Logging Vs. NLog

With NLog you could do: var logger = NLog.LogManager.GetCurrentClassLogger(); logger.Info(“Hello {Name}”, “Earth”); That works for all platforms and all frameworks. Microsoft.Extensions.Logging With .NET Core, Microsoft introduced the ILogger abstraction from Microsoft.Extensions.Logging. You could use that logging abstraction in your project and integrate it with NLog. For example in ASP.NET Core you could inject Microsoft.Extensions.Logging.ILogger<HomeController> and … Read more

Use NLog in ASP.NET Core application

For ASP.NET Core, you need NLog.Web.AspNetCore – which has a dependency on NLog.Extensions.Logging. Note: Microsoft.Framework.Logging.NLog has been replaced by NLog.Extensions.Logging on NuGet, which is maintained by the NLog team. How to use: Setup NLog needs to be enabled so it will integrate into the DI and log API of ASP.NET Core. This will result that … Read more