Sampling in SerilogTracing is taking shape. If you haven’t heard of SerilogTracing, that’s not surprising - it’s a brand new project launched in January 2024 . But, we’ve reached 250k downloads of the core package , and we’re still picking up steam. 😎 This post takes a look at the sampling functionality that’s arrived in SerilogTracing 2.2. Trace sampling There are a few things we can do to…
Distributed tracing can generate a lot of data, and sampling is the most established method to keep data volumes manageable. In .NET, the System.Diagnostics.ActivityListener class exposes two properties to control sampling: Sample , and SampleUsingParentId . How do these work? If you just switched browser tabs to check the documentation, I know why you’re back. There’s barely any useful…
This is a quick post exploring how Serilog 4.1 (currently in preview) schedules retries when logging fails. Logs tucked away in a file on a remote server aren’t very useful, so sending log events across a network to a centralized collector, log server, or service is very common. But, networks are unreliable and services have outages, so logging systems need to support retries when a network…
Currently in preview , Serilog 4.1 adds support for falling back to a second sink when the first sink fails. This scenario shows up in a few variations, usually revolving around a network-based log collector, and a local, persistent destination such as a rolling log file that’s used when the network-based collector is unavailable. Some low-volume scenarios use email logging or a Slack channel as…
ASP.NET Core keeps evolving, and it’s been a while since I wrote one of these , so read on below for my take on an optimal Serilog configuration for ASP.NET Core 8 and the “minimal API” application model, a.k.a. WebApplicationBuilder . I’ve arranged this into three parts: configuring Serilog, hooking up Microsoft.Extensions.Logging.ILogger<T> , and recording web requests. Each part builds on the…
SerilogTimings is a handy little library that wraps blocks of code in “operations”: using Serilog ; using SerilogTimings ; Log . Logger = new LoggerConfiguration () . WriteTo . Console () . CreateLogger (); using ( Operation . Time ( "Say hello to {Name}" , Environment . UserName )) { Log . Information ( "Hello!" ); using ( var op = Operation . Begin ( "Measure temperature" )) { // Attached to the…
If you want to record a log event from your application in .NET, you can do that today without a lot of noise or ceremony using Microsoft.Extensions.Logging : _log . LogInformation ( "Completing order {OrderId} for {Customer}" , order . Id , order . Customer ); Admittedly it’s a long line, but from this statement, packed in alongside the timestamp, level, and whatever correlation identifiers are…
TL:DR: Check out SerilogTracing , a simple, minimal extension for Serilog that integrates with System.Diagnostics.Activity to provide hierarchical, distributed traces and compatibility with the Serilog sink ecosystem. Traces are amazing for analyzing performance and for describing complex operations that flow across multiple systems. Modern .NET has tracing support built-in, so it’s now…
👋 Howdy! I hope you’re enjoying the, frankly, pretty fantastic state of structured logging in .NET these days. If you’re using Serilog then I hope you’ve also been enjoying the long period of stability we’ve maintained on the 2.x release series (I don’t want to rewrite my application logging every eighteen months, either 🙂). While we’ve been keeping Serilog fresh, it’s time to make some minor…
Hi! 👋 Chances are you’ve found your way here because Serilog.Settings.Configuration ’s runtime reconfiguration logic only supports minimum levels, and not any other sink parameters. This stems from a strong preference for immutability (and hence clean concurrency) in the Serilog design, but the question remains: if I need to update a sink parameter at runtime, how can I do that? Sinks and…