如何使用.net3.1中的c#控制台应用程序中的docker创建serilog logger文件
我想使用Docker Image创建Serilog Logger文件。我能够在控制台应用程序中创建一个文件,但无法使用Docker创建文件。 这是我的示例代码,
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
.WriteTo.File(fileName, rollingInterval: RollingInterval.Day)
.WriteTo.File(@"C:\log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
I want to create serilog logger file using docker image. I am able to create a file in console app but not able to create using docker.
Here is my sample code,
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
.WriteTo.File(fileName, rollingInterval: RollingInterval.Day)
.WriteTo.File(@"C:\log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,Docker的想法是将应用程序与正在运行的主机隔离。您的应用程序正在尝试访问位于主机而不是容器上的“ C:\ log.txt”文件。您可以通过指定诸如'/app/log.txt'之类的路径(注意linux型)来写入容器内的文件。
如果您确实需要主机端日志文件,则需要更复杂的方法 - 因此答案可能会有所帮助:
在Docker容器之外露出日志文件
In short, the docker idea is to isolate the application from the host it is running on. Your app is trying to access the 'c:\log.txt' file which resides on host, not the container. You can write to the file inside the container by specifying the path like '/app/log.txt' (note the linux-style).
If you really need the host-side log file, the more complicated approaches are required - this SO answer may help:
Expose log file outside docker container