【问题标题】:serilog and seq in webapi project, no log entry appearwebapi项目中的serilog和seq,没有出现日志条目
【发布时间】:2022-09-28 01:45:22
【问题描述】:

我使用我的 Webapi (.net 6) 项目进行了 Serilog 设置。目前它正在正确写入控制台和文件,但是当我尝试使用 Seq 进行设置时,我看不到文件中出现的任何条目:

我的应用设置:

 {
  \"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/\"
        }
      }
    ]
  }
}

我在 docker 容器中运行 Seq,并且能够使用 http://localhost:8081/ 启动它。我看到了仪表板和事件部分,但那里什么也没有出现,两者都是空的。

以下是我正在输入的日志示例:

    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());
    }

我在我的文件中看到警告消息,但从未在 Seq.有人建议需要 CloseAndFlush 记录器,但这些建议是针对控制台应用程序的。

我使用的 docker 命令是:

docker run -d --restart unless-stopped --name seqtest -e ACCEPT_EULA=Y -p 8081:80 datalust/seq:latest
  • 您如何在项目中包含“Serilog.Sinks.Seq”。它是否在您运行应用程序的当前目录中可用。
  • @CodingMytra 就像你提到的那样,我忘了包括水槽。如果您想回复,我可以将其标记为答案。
  • 我已添加为答案。

标签: asp.net asp.net-web-api sequence serilog


【解决方案1】:

为了使其工作,您需要在项目参考中添加Serilog.sink.seq。这样所需的 dll 就会被复制到输出文件夹。

希望能帮助到你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-05
    • 2021-09-18
    • 1970-01-01
    相关资源
    最近更新 更多