[DotNetCore] Refactor Serilog ApplicationInsights and AzureAnalytics to extensions
kdcllc opened this issue · 0 comments
kdcllc commented
At the moment there is no way to use Serilog with IHost
for
- Serilog.Sinks.ApplicationInsights
- Serilog.Sinks.AzureAnalytics
Refactor func to Bet.Extensions.Logging
Add this package to support the functionality
<PackageReference Include="Serilog.Extensions.Hosting" Version="3.0.0" />
Final result should be
return Host.CreateDefaultBuilder(args)
.UseSerilog((hostingContext, loggerBuilder) =>
{
var applicationName = $"Worker-{hostingContext.HostingEnvironment.EnvironmentName}";
loggerBuilder
.ReadFrom.Configuration(hostingContext.Configuration)
.Enrich.FromLogContext()
.WriteTo.Console()
.AddApplicationInsights(hostingContext.Configuration)
.AddAzureLogAnalytics(hostingContext.Configuration, applicationName: applicationName);
});