【问题标题】:ASP.Net Classic Serilog not writing to fileASP.Net Classic Serilog 不写入文件
【发布时间】:2021-09-15 08:19:12
【问题描述】:

我正在尝试创建一个具有统一性的 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 的目录中看到一个日志文件 但什么都没有。我错过了什么?

【问题讨论】:

  • {Date} 之间应该有空格吗?

标签: c# asp.net logging log4net serilog


【解决方案1】:

找到了。路径组合仅在第二个参数不是绝对路径时才有效。所以我不得不删除“@”

我必须成功

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

【讨论】:

    猜你喜欢
    • 2022-10-24
    • 1970-01-01
    • 2021-08-18
    • 2018-02-03
    • 2021-10-11
    • 1970-01-01
    • 2022-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多