Writing Structured and Correlated Logs
Distributed tracing is a great tool to describe and correlate operations, but sometimes, we need to record things such as callbacks and startup configurations, or conditionally write debug information. In this chapter, we’re going to explore logs – the oldest and most popular telemetry signal that can describe anything.
First, we’ll talk about logging use cases and discover different APIs available in .NET, and then we’ll focus on ILogger
– a common logging façade. We’ll learn how to use it efficiently to write structured events. We’ll see how to export logs with OpenTelemetry and write rich queries over them. Finally, we’ll explore log sampling and cost-saving strategies.
In this chapter, you’ll learn the following:
- When to write logs and which .NET API to use
- How to write logs with the
Microsoft.Extentions.Logging.ILogger
class - How to capture and export...