如何解决ASP.Net Classic Serilog 不写入文件
我正在尝试创建一个具有统一性的 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")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。