ServiceStack结构化日志记录

问题描述 投票:3回答:1

[例如,如何使用Serilog与Servicestack?

来自Serilog和NLog的示例都具有Log.Information("Hello World from {FirstName}", "Thomas");的形式,我无法在ServiceStack中找到匹配的方法签名。

servicestack
1个回答
3
投票

[enhanced Serilog Logging APIs显示Serilog Enrichers示例时,请参阅existing StackOverflow answer的日志记录文档。

[SerilogLoggerTests.cs显示了使用Serilog的不同示例:

var log = new SerilogLogger(GetType());

const string message = "Error Message";
const string messageFormat = "Message Format: message: {0}, exception: {1}";

var ex = new Exception();
log.Info(message);
log.Info(message, ex);
log.InfoFormat(messageFormat, message, ex.Message);
log.Info(ex, messageFormat, messageFormat, ex);

以及具有自定义属性的Log Context示例:

var log = new SerilogLogger(new LoggerConfiguration()
    .WriteTo.Sink(sink).CreateLogger());

var messageTemplate = "Testing adding {prop2} props";
log.ForContext("prop", "value").InfoFormat(messageTemplate, "awesome");

还有PushProperty()个API来分配自定义属性,有关示例,请参见Serilog's Enrichment docs

© www.soinside.com 2019 - 2024. All rights reserved.