Search code examples
kubernetes.net-coreserilog

How to log with Serilog to a remote server?


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.


Solution

  • 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?