Reputation: 3289
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.
Upvotes: 1
Views: 3658
Reputation: 584
For Linux Host :
Change folder permission to 777 where you want to store logs.
chmod 777 .
docker run -d -t -i -p 80:80 -v /usr/Logs:/app/Logs --name testContainer testImage
Upvotes: 0
Reputation: 30056
Follow steps below to check the difference.
Configure Serilog
like
public 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
Upvotes: 3