-
Book Overview & Buying
-
Table Of Contents
Apps and Services with .NET 10 - Third Edition
By :
The most obvious reason for logging is to understand what went wrong and when. In .NET, exceptions can be caught, and stack traces can be printed, but that’s often not enough context. Although .NET includes logging frameworks, third-party logging providers give more power and flexibility by using structured event data. Serilog is the most popular.
Most systems write plain text messages to their logs.
Serilog can be told to write serialized structured data to the log. The @ symbol prefixing a parameter tells Serilog to serialize the object passed in, instead of just the result of calling the ToString method.
Later, that complex object can be queried for improved search and sort capabilities in the logs.
For example:
var lineitem = new { ProductId = 11, UnitPrice = 25.49, Quantity = 3 };
log.Information("Added {@LineItem} to shopping cart.", lineitem);
You can learn more about how...