我正在编写MVC应用程序,使用serilog将日志写入mssql。 当我调用某些方法时,它们没有出现在日志中,只有第一个出现。 有任何想法吗?
public Startup(IConfiguration configuration)
{
Configuration = configuration;
var listener = new global::SerilogTraceListener.SerilogTraceListener();
Trace.AutoFlush = true;
Trace.Listeners.Add(listener);
Log.Logger = new LoggerConfiguration()
.AuditTo
.MSSqlServer(
connectionString: configuration.GetConnectionString("DefaultConnection"),
tableName: "Logs", autoCreateSqlTable: true, schemaName: "Diagnostics",
restrictedToMinimumLevel: LogEventLevel.Verbose)
.MinimumLevel.Verbose()
.Enrich.WithThreadName()
.Enrich.WithThreadId()
.Enrich.FromLogContext()
.WriteTo.Trace()
.CreateLogger();
}//end ctor
在HomeController中:
private readonly ILogger<HomeController> logger;
public HomeController(ILogger<HomeController> logger)
{
this.logger = logger;
}
public IActionResult Index()
{
TryExecute();
return View();
}
public void TryExecute()
{
//logger.LogInformation("try me here not async");
}
数据库中的结果: https://imgur.com/7mV2pin
如您所见,索引方法的执行已记录下来,但TryExecute却没有... 我该怎么办?