1

I'm writing a .NET Core 6 Web API and decided to use Serilog for logging. This is how I configured it in appsettings.json:

"Serilog": {
    "Using": [ "Serilog.Sinks.File" ],
    "MinimumLevel": {
        "Default": "Information"
    },
    "WriteTo": [
        {
            "Name": "File",
            "Args": {
                "path": "../logs/webapi-.log",
                "rollingInterval": "Day",
                "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3}] {Username} {Message:lj}{NewLine}{Exception}"
            }
        }
    ]
}

This is working fine, it's logging inside a logs folder in the root.

Now I've deployed my API to a Staging K8s cluster and don't want my logs to be stored on the pod but rather on the Staging server. Is it possible? I can't find many useful posts about it, so I assume there is a better way to achieve it.

cs.kali
  • 198
  • 12
  • 2
    Writing to a log is no different to writing to any other file. If a remote server folder is mounted, you can write to it the same way you would to a local file, just by supplying the path. If you use K8s though, you probably want the log files to go to an Elastic server. There's a sink for this too. Another option is logging to the console using eg a Logstash formatter and having Docker/K8s log the standard out output to a file – Panagiotis Kanavos Dec 23 '22 at 11:27

1 Answers1

0

Based on Panagiotis' 2nd suggestion I spent like a week to try to set up Elasticsearch with Fluentd and Kibana with no success.

Turned out, that the simplest and easiest solution was his 1st one: all I needed was a PersistentVolume and a PersistentVolumeClaim. This post helped me with the setup: How to store my pod logs in a persistent storage?

cs.kali
  • 198
  • 12