I'm trying to use Serilog and Ninjet on a C# Windows client (forms) application using .Net 6.0
Can anyone tell me how I configure Ninject so that ILogger is injected here:
public partial class TestingForm : Form
{
private readonly ILogger<TestingForm> _logger;
TestingForm(ILogger<TestingForm> logger)
{
_logger = logger;
}
//etc.
}
I was rather hoping to use something like the .UseSeriLog() used here:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
from https://www.ezzylearning.net/tutorial/logging-in-asp-net-core-5-using-serilog but I just can't work out how to do it with Ninject
I created a Windows forms app targeting .NET 6. I installed Serilog and Ninject through Nuget.
MyModule.cs:
Programs.cs:
Serilog.cs
Serilog's ILogger is non-generic so just use ILogger. If you want ILogger of type TestingForm then you probably need to install Microsoft.Extensions.Logging.