# Templates for logging configurations

Different templates for the logging configuration are listed on this page. Many of these templates can simply be copied to replace an existing logging configuration.

# Log overflow

The log is written to a file that overflows each day or after 75 megabytes.

{
  "Serilog": {
    "Using": [
      "Serilog.Sinks.File"
    ],
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "File",
        "Args": {
          // 75 MiB file size limit
          "fileSizeLimitBytes": 78643200,
          "retainedFileCountLimit": 20,
          "path": "Logs/ELOSync.log",
          "rollingInterval": "Day"
        }
      }
    ],
    "Enrich": [
      "FromLogContext",
      "WithMachineName",
      "WithThreadId"
    ],
    "Properties": {
      "Application": "ELO Sync"
    }
  }
}

# Plain console output

The log is only written to the console output (stdout) of the ELO Sync process.

{
  "Serilog": {
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "Console"
      }
    ],
    "Enrich": [
      "FromLogContext",
      "WithMachineName",
      "WithThreadId"
    ],
    "Properties": {
      "Application": "ELO Sync"
    }
  }
}

# Asynchronous console output

The log is only written on the console output (stdout), but asynchronously, preventing logging itself from slowing down the process significantly. The greatest disadvantage is that log messages can be written in the wrong order.

{
  "Serilog": {
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "Async",
        "Args": {
          "configure": {
            "Name": "Console"
          }
        }
      }
    ],
    "Enrich": [
      "FromLogContext",
      "WithMachineName",
      "WithThreadId"
    ],
    "Properties": {
      "Application": "ELO Sync"
    }
  }
}

# Console output in JSON format

The log is only written to the console output (stdout) in JSON format.

{
  "Serilog": {
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "formatter": "Serilog.Formatting.Json.JsonFormatter"
        }
      }
    ],
    "Enrich": [
      "FromLogContext",
      "WithMachineName",
      "WithThreadId"
    ],
    "Properties": {
      "Application": "ELO Sync"
    }
  }
}

# Console output in compact JSON format (CLEF)

The log is only written to the console output (stdout) in the JSON-based CLEF format.

{
  "Serilog": {
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
        }
      }
    ],
    "Enrich": [
      "FromLogContext",
      "WithMachineName",
      "WithThreadId"
    ],
    "Properties": {
      "Application": "ELO Sync"
    }
  }
}

# Console output in the CLEF format and log overflow

An example for combining multiple log outputs.

{
  "Serilog": {
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
        }
      },
      {
        "Name": "File",
        "Args": {
          // 75 MiB file size limit
          "fileSizeLimitBytes": 78643200,
          "retainedFileCountLimit": 20,
          "path": "Logs/ELOSync.log",
          "rollingInterval": "Day"
        }
      }
    ],
    "Enrich": [
      "FromLogContext",
      "WithMachineName",
      "WithThreadId"
    ],
    "Properties": {
      "Application": "ELO Sync"
    }
  }
}
Dernière mise à jour: 21 février 2025 à 09:59