简体   繁体   中英

How to create a serilog logger file using docker in C# console Application with .Net3.1

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();

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM