Serilog UdpSysLog Missing Logs Serilog.Sinks.SyslogMessages

Viewed 60

Update: Not a serilog issue. Tried TCP and the problem persisted. Turned out the log server was maxing out CPU so the logs were being lost. This problem didn't appear in log4net as it is blocking which limited the rate at which logs were sent. Solution is to up the spec of log server.

Recently started to use Serilog UdpSysLog for logging from .Net6.0 Console/Web Applications.

We noticed that sometimes there logs are missing. If we send a burst of logs for some reason there would be a random amount missing each time.

An example of a large burst would be if we were processing a file and there are difference to values. Each difference would be its own log so we could be sending up to 4000 logs.

While the logs are missing when using UdpSysLog they work fine when writing the file locally.

We swapped out serilog for log4net and could not reproduce the behaviour.

csproj

    <PackageReference Include="Serilog" Version="2.11.0" />
    <PackageReference Include="Serilog.Sinks.SyslogMessages" Version="2.0.6" />
    <PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
    <PackageReference Include="Serilog.Enrichers.Thread" Version="3.2.0-dev-00752" />
    <PackageReference Include="Serilog.AspNetCore" Version="6.0.0-dev-00265" />

appsettings.json

  "Serilog": {
    "WriteTo": [
      {
        "Name": "File",
        "Args": {
          "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff}||{Level:u3}||{Product}||{Application}||{EnvironmentName}||{MachineName}||{ThreadId}||{CorrelationId}||{SourceContext}||{Message}{Exception}{NewLine}",
          "path": "d:/loggingapp-.txt",
          "retainedFileCountLimit": 7,
          "rollingInterval": "Day"
        }
      },
      {
        "Name": "UdpSyslog",
        "Args": {
          "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff}||{Level:u3}||{Product}||{Application}||{EnvironmentName}||{MachineName}||{ThreadId}||{CorrelationId}||{SourceContext}||{Message}{Exception}{NewLine}",
          "host": "hostname",
          "port": 514
        }
      }
    ]
  }

Project.cs (Serilog setup)

var _builder = new ConfigurationBuilder();

_builder.SetBasePath(Directory.GetCurrentDirectory())
                    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                    .AddEnvironmentVariables();

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
    .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
    .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
    .Filter.ByExcluding(Matching.WithProperty("RequestPath", "/healthz"))
    .Enrich.WithProperty("Application", "Serilog")
    .Enrich.WithProperty("Product", "LoggingTestApp")
    .Enrich.WithEnvironmentName()
    .Enrich.WithMachineName()
    .Enrich.WithThreadId()
    .Enrich.FromLogContext()
    .ReadFrom.Configuration(_builder.Build())
    .CreateLogger();

var _host = Host.CreateDefaultBuilder()
            .ConfigureServices((context, services) => {
                services.AddTransient<LoggingTestApp.IWorkflow, LoggingTestApp.Workflow>();
            })
            .UseSerilog()
            .Build();
0 Answers
Related