我在我的AspNetCore 3.1 Web API中实现了Serilog。我的第一个想法是登录到Mssql。但是当我将代码写到正确的位置时,应用程序无法启动。
我的启动文件是:
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>();
});
}
在按下F5按钮后,调试控制台停留在此行:
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.
我在哪里弄错了?
答案 0 :(得分:0)
我在使用 Serilog 时遇到了同样的问题。看来 UseSerilog() 语句需要通过它传递更多信息。 The docs provide an example of this. 我能够使用
来运行我的程序.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.WriteTo.Console())