I use Serilog as logging library and that is working fine also with Docker. It creates all log files as requested. I mount a directory from the host system into my container like so:
And what drives me really crazy: If I run it on my Linux Workstation it works and creates a folder requestlogs and there a folder 2018-11 and there I can find a file called 2018-11-16.csv. But as soon as it runs in docker it does nothing but also no error is thrown anywhere.
Does the ServiceStack Virtual File System have a problem with Docker? Or is there any special configuration required??
It should not be stored in the container, it must be written to the HOST, otherwise the stuff is gone when you remove the container.
To achieve that you have to map a folder of the host into your container. That is done in the docker run command with -v /root/Projects/logs:/logs. So in the container I can cd to /logs and I am effectively on my Docker host.
My project is stored in a folder called app in the container. I tried to enable the plugin with the default constructor (no parameters passed). When running on my Linux box, it creates the sub-folders in the project folder. This does NOT work as soon as it is running in Docker. Looks like FileSystemVirtualFiles is refusing any work when running in Docker!
Don’t just assume the issue is Docker, the FileSystemVirtualFiles uses .NET File System APIs like everything else, if you’re having issues and the absolute path is valid from within the container check that you have read/write access to it from the .NET Core App (e.g. test reading/writing to it using .NET’s File APIs in Program.cs).
Yeah thats why I am so confused, I configured serilog the same way and it works. I am assuming it is using normal .NET APIs.
Now I added the following lines in apphost.cs just before registering the RequestLog plugin:
Logger.Debug($"Logpath: {logpath}");
var fs = new FileSystemVirtualFiles(logpath);
var testfile = "/testfolder/helloworld.txt";
var filecontent = "Hello World!";
Logger.Debug($"Writing test file '{testfile}' with content '{filecontent}' to '{fs.RootDirectory.RealPath}'");
fs.WriteFile(testfile, filecontent);
Plugins.Add(new RequestLogsFeature
{
RequestLogger = new CsvRequestLogger(fs)
});
I rebuilt everything and pushed it to my docker registry (quay.io).
Then I pulled that container from another linux box and called my service with /metadata and bingo IT WORKS! The hello world file was created and also the request CSV was created. No idea what is not working in the datacenter. I have to try again. If it is not working there these guys need to check for reasons since they setup fancy firewall rules and SELinux etc…