簡體   English   中英

ASP.Net Classic Serilog 不寫入文件

[英]ASP.Net Classic Serilog not writing to file

我正在嘗試創建一個統一的 ilogger 並且我已經創建好了,但是當我調用記錄器時,沒有任何內容寫入文件。 我錯過了什么?

這是我的團結

container.RegisterType<ILogger>(new ContainerControlledLifetimeManager(), new InjectionFactory((ctr, type, name) => {

ILogger log = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithThreadId()
.Enrich.WIthProperty("ApplicationVersion", GetApplicationVersion())
.WriteTo
  .Logger(lc => lc.Filter
                .ByIncludingOnly(e => e.Level == LogEventLevel.Information || e.Level == LogEventLevel.Debug)
.WriteTo.RollingFile(Path.Combine(path, @"\infolog -{ Date}.txt")))
.CreateLogger();

return log;
}));

然后在我的控制器中注入它

MyClass(ILogger ilog){
_ilog = ilog;
}

public void DoSomething(){
this._ilog.Information("logged message");
}

我希望在名為 Errorlogs/info-07032021.txt 的目錄中看到一個日志文件,但那里什么也沒有。 我錯過了什么?

找到了。 路徑組合僅在第二個參數不是絕對路徑時才有效。 所以我不得不刪除“@”

我必須做到

   .WriteTo.RollingFile(path + "\infolog -{ Date}.txt")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM