Search code examples
asp.netasp.net-web-apisequenceserilog

serilog and seq in webapi project, no log entry appear


I have Serilog setup using my Webapi (.net 6) project. Currently it is writing to the Console and File properly, but when I'm trying to set it up with Seq I don't see any of the entries that appear in the File:

my appsettings:

 {
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning",
      "TestProj": "Information"
    }
  },
  "Serilog": {
    "MinimumLevel": "Information",
    "WriteTo": [
      {
        "Name": "Console"
      },
      {
        "Name": "File",
        "Args": {
          "path": "logs/testlog_d.txt",
          "rollingInterval": "Day",
          "restrictedToMinimumLevel": "Warning"
        }
      },
      {
        "Name": "Seq",
        "Args": {
          "serverUrl": "http://localhost:8081/"
        }
      }
    ]
  }
}

I'm running Seq in a docker container and am able to bring it up using http://localhost:8081/ I see the dashboard and events sections, but nothing appears there, both are empty.

The below is a sample of a log I'm entering:

    public WeatherForecastController(ILogger<WeatherForecastController> logger, IWeatherService weatherService)
    {
        _logger = logger;
        _weatherService = weatherService;
    }

    [HttpGet]
    [Route("getweatherforecast")]
    public ActionResult<IEnumerable<WeatherForecast>> Get()
    {
        _logger.LogInformation("Called Get Method");
        _logger.LogWarning("This is a test warning method");
        return Ok(_weatherService.GetWeatherSummary());
    }

I see the Warning message in my File, but never in Seq. There were suggestions about needing to CloseAndFlush the logger, but those were for console apps.

The docker command I used was:

docker run -d --restart unless-stopped --name seqtest -e ACCEPT_EULA=Y -p 8081:80 datalust/seq:latest

Solution

  • In order to make it work, you need to add the Serilog.sink.seq in your project reference. So that required dll gets copied to output folder.

    Hope it helps.