serilog-sinks-mysql
serilog-sinks-mysql copied to clipboard
The master branch not work with asp.net core
Hi saleem,
it seems master banch can't work with asp.net core, and the latest nuget also not work, but when i switch to dev branch, it worked. I tried to find the root cause but didn't find it. Do you know the reason?
there is the program code.
public class Program
{
public static void Main(string[] args)
{
args.SetConfigInfo();
var logConfig = new LoggerConfiguration()
#if DEBUG
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
#else
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
#endif
.Enrich.FromLogContext();
logConfig = ConfigDataHelper.TryGetConnectionString("iBlogs", out var connectionString) ?
logConfig.WriteTo.MySQL(connectionString) : logConfig.WriteTo.Console();
Log.Logger = logConfig.CreateLogger();
try
{
Log.Information("Starting web host");
CreateWebHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.AddCommandLine(args);
})
.UseStartup<Startup>()
.UseSerilog();
}