Search code examples
.netloggingfilenamesserilog

What file name placeholders are available for Serilog?


I use Serilog on a .NET Core application with RollingFile. I wonder, if there are different filename placeholders? I only know {Date}.

For example, I have code like

        Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Information()
            .WriteTo.RollingFile("Logs/{Date}.log")
            .CreateLogger();

Are there any other options for the filename like {Date}? I'd like to have log files by hour.


Solution

  • At the time of this writing, Serilog's Rolling File sink supports 3 (three) specifiers:

    • {Date}, which is formatted as yyyyMMdd
    • {Hour}, which is formatted as yyyyMMddHH
    • {HalfHour}, which is formatted as yyyyMMddHHmm

    You can see it in the README of the Rolling File sink, as well as in the source code of the Rolling File sink.