docker - Log file not created in a .NET Core application running in a Docker container
问题描述
I run a ASP.NET Core
application in a Docker container
and I am using Serilog.Extensions.Logging.File
to write logs to a file.
I am able to see the logs when running the app locally (not in a container), but I am not able to see the logs when I bash into the container.
I am new to containerization and I was wondering if I am missing any steps.
解决方案
Follow steps below to check the difference.
Configure
Serilog
likepublic static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .ConfigureLogging((hostingContext, builder) => { builder.AddFile("Logs/myapp-{Date}.txt"); }) .UseStartup<Startup>();
Build the image
docker build -t dockersql .
Run the image
docker run -it -p 9999:80 dockersql
Find the running container and exec the container
As the suggestion from @Chris, it is recommended to mount the volume, you could try like
docker run -it -p 9999:80 -v D:\xx\TestDockerSQL\Test:/app/Logs dockersql
推荐阅读
- docker - 如何使用awx cli?
- c# - Linq:一个匿名类型不能有多个同名的属性
- ruby-on-rails - 使用 rails sunspot 过滤搜索结果中的关联
- android - 安卓分线器
- python-3.x - Python3.8 Round with decimal Constructor with Float or String
- java - Java 中的 rawtypes 警告的弃用 API
- javascript - ReactJS表单性能问题更新状态对象数组
- c++ - 顺便说一句原子交换(没有返回值)和存储的区别?这是关于带有原子库的彼得森算法
- r - R中的字符串删除
- html - Html 表单堆叠得太近了