From SerilogTimings to SerilogTracing
Nicholas Blumhardt
by
3w ago
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 log event but not shown in text output op.Complete("Temperature", 35); } } When an operation completes, either explicitly or by being disposed, SerilogTimings writes an event with ..read more
Visit website
The case for an application-level tracing API in .NET
Nicholas Blumhardt
by
1M ago
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 set behind the scenes, you get: A human-friendly message — "Completing order 15 for nblumhardt" A low-cardinality event type — "Completing order {OrderId} for {Customer}" A fully-structured payload — {"OrderId ..read more
Visit website
SerilogTracing
Nicholas Blumhardt
by
2M ago
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 surprisingly easy to generate and consume traces with all of the hierarchical, distributed goodness provided for free by the framework. SerilogTracing is a new project that handles the mechanics of: Creating ..read more
Visit website
Serilog project update, May 2023
Nicholas Blumhardt
by
11M ago
? 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 breaking changes, particularly in the target frameworks and library versions that the mainline Serilog packages will support. A few interesting things are coming in the next month or so, and so here’s a q ..read more
Visit website
Hot-reload any Serilog sink
Nicholas Blumhardt
by
1y ago
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 configuration Serilog sinks often need to be configured with some information about where a log event should be sent. The Seq sink, for example, accepts a URL and optional API key for the target Seq server ..read more
Visit website
Customized JSON formatting with Serilog
Nicholas Blumhardt
by
3y ago
TL;DR: Another Serilog Expressions by example post, showing how to produce newline-delimited JSON logs from Serilog events. Newline-delimited JSON is a useful format for structured logs that will be read by other applications. Serilog’s built-in JsonFormatter implements this, but to my eyes, its output is awkward and verbose. The newer CompactJsonFormatter and RenderedCompactJsonFormatter in Serilog.Formatting.Compact produce cleaner JSON, and that format is supported by other tools in the Serilog ecosystem and beyond, so they’re a better starting point. Because they implement a standardized ..read more
Visit website
Customizing Serilog text output
Nicholas Blumhardt
by
3y ago
TL;DR: Everything you need to know about formatting plain text with Serilog.Expressions, by example. There are endless ways to format log output. With Serilog’s built-in “output templates”, you can choose the fields and text to include in log output, and use .NET format string-style alignment and width syntax, but that’s about it. Serilog.Expressions is a fairly new library that plugs in to enable everything else. This post collects the plain text formatting questions I’ve fielded over the years, and their solutions using Serilog.Expressions. I’ve tried to keep everything short and pithy, so ..read more
Visit website
Serilog.Expressions 2.0 update
Nicholas Blumhardt
by
3y ago
Serilog.Expressions is a little library that implements expression-based filtering and formatting of structured log events. // dotnet add package serilog.expressions // dotnet add package serilog.sinks.console // using Serilog; using var log = new LoggerConfiguration() .Filter.ByExcluding("@m like 'Hello%' and Name = 'world'") .WriteTo.Console() .CreateLogger(); // Logged normally log.Information("Hello, {Name}!", "reader"); // Excluded by the filter log.Information("Hello, {Name}!", "world"); It’s useful for configuring Serilog in appsettings.json or Web.config files, so spe ..read more
Visit website
Bootstrap logging with Serilog + ASP.NET Core
Nicholas Blumhardt
by
3y ago
Errors during application start-up are some of the nastiest problems to hit in production. Deployment issues like broken manifests or missing assemblies, incorrect settings, exceptions thrown during IoC container configuration or in the constructors of important components - these can bring start-up to a screeching halt and cause a process exit, without leaving even so much as an error page. Ideally, though, your logging infrastructure will have your back, and collect the information you need to diagnose the issue. This is why Serilog is — ideally — set up on the very first line of Main(): p ..read more
Visit website
User-defined functions in Serilog Expressions
Nicholas Blumhardt
by
3y ago
Yesterday’s post introduced Serilog Expressions, a little library for filtering, enriching, and formatting Serilog events. We left open the question of how to show dates and times in UTC. This is a good fit for a user-defined function: writing and plugging-in our own implementation of ToUtc() is the subject of this post. A recap of ExpressionTemplate ExpressionTemplate turns Serilog events into plain text or JSON by executing a template. Here’s an example that shows how log events might be formatted for display at the terminal: // dotnet add package serilog.expressions -v 1.0.0-* using Seril ..read more
Visit website

Follow Nicholas Blumhardt on FeedSpot

Continue with Google
Continue with Apple
OR