❔ Setting Up NLog with DI

I have my appsettings.json all set-up, and I have installed the nlog nuget. How do I set-up NLog to use with DI something similar to the below?
public static void Main(string[] args)
{
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
services.AddSingleton<ProcessingService>();
services.AddSingleton<Utilities>();
// services.AddSingleton<NLog>();
})
.Build();

host.Run();
}
public static void Main(string[] args)
{
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
services.AddSingleton<ProcessingService>();
services.AddSingleton<Utilities>();
// services.AddSingleton<NLog>();
})
.Build();

host.Run();
}
3 Replies
Saber
Saber2y ago
Did you consider looking at the documentation? I'd also recommend serilog over nlog
FoxTrotCharlieZulu
what makes serilog better?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.