I like to implement log data from client (WASM) into a backend file using Serilog as descripted here. At my program.cs (server app) I got already that:
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
#if RELEASE
webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
webBuilder.UseIISIntegration();
#endif
webBuilder.UseStartup<Startup>();
})
When I add the code for Serilog...:
.UseSerilog().ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
... I get the exception:
System.ArgumentException: 'An item with the same key has already been added. Key: ConnectionStrings'
The reason is because Startup is called two times and the config data are written two times and so the keys are already been added.
Do you know a way to solve this problem?
How I should manipulate the UseSerilog().ConfigureWebHostDefaults()?
Can I just delete one of both webBuilder.UseStartup();?
(Existing logic should remain and Serilog should be added).