Reputation: 1765
How can I get structured logging when using e.g. Serilog with Servicestack?
The examples from both Serilog and NLog have the form Log.Information("Hello World from {FirstName}", "Thomas");
for which I cannot find a matching method signature in ServiceStack.
Upvotes: 3
Views: 172
Reputation: 143339
See logging docs for enhanced Serilog Logging APIs whilst this existing StackOverflow answer shows a Serilog Enrichers example.
SerilogLoggerTests.cs shows different examples of using 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);
and a Log Context example with custom properties:
var log = new SerilogLogger(new LoggerConfiguration()
.WriteTo.Sink(sink).CreateLogger());
var messageTemplate = "Testing adding {prop2} props";
log.ForContext("prop", "value").InfoFormat(messageTemplate, "awesome");
There's also PushProperty()
APIs to assign custom properties, see Serilog's Enrichment docs for examples.
Upvotes: 3