I implement the Serilog into my AspNetCore 3.1 Web API. My first idea is logging to Mssql. But when i write the code into right place, application does not start.
My Startup file is:
public class Program
{
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Seq("http://localhost:5341").CreateLogger();
try
{
Log.Information("Host starting...");
Serilog.Debugging.SelfLog.Enable(msg =>
{
Debug.Print(msg);
Debugger.Break();
});
CreateHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
And after hit the F5 button, debug console has stuck at this line:
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.4/System.Runtime.Numerics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Where am I making a mistake?
I had the same issue when using Serilog. It appears that the UseSerilog() statement needs more information passed through it. The docs provide an example of this. I was able to get my program running by using
.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.WriteTo.Console())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.