Verify.Serilog
May 15, 2026 ยท View on GitHub
Extends Verify to allow verification of Serilog bits.
See Milestones for release notes.
Sponsors
Entity Framework Extensions
Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.
Developed using JetBrains IDEs
NuGet
Usage
Setup
Use VerifySerilog.Initialize()
[ModuleInitializer]
public static void Initialize() =>
VerifySerilog.Initialize();
Or omit the above is VerifierSettings.InitializePlugins(); is called:
[ModuleInitializer]
public static void Initialize() =>
VerifierSettings.InitializePlugins();
LoggerConfiguration callback
VerifySerilog.Initialize accepts an optional Action<LoggerConfiguration> callback for customising the underlying Serilog LoggerConfiguration โ for example to register destructuring policies, enrichers, or filters. The callback runs after MinimumLevel.Verbose, Enrich.FromLogContext, and the VerifySink have been wired up, so it can layer on top of those defaults.
[ModuleInitializer]
public static void Initialize() =>
VerifySerilog.Initialize(
_ => _.Destructure.ByTransforming<Customer>(
customer => new
{
customer.Name
}));
Ignoring messages by SourceContext
VerifySerilog.IgnoreSourceContext filters out log events whose SourceContext property matches a known type or string. Generic and string overloads are provided. Typically called from the module initializer alongside Initialize.
VerifySerilog.IgnoreSourceContext<MyNoisyType>();
VerifySerilog.IgnoreSourceContext("Some.Namespace.Logger");
Events emitted via Log.ForContext<T>() or Log.ForContext("SourceContext", "...") whose source context matches are dropped before being recorded.
Recording and writing logs
[Test]
public Task Usage()
{
Recording.Start();
var result = Method();
return Verify(result);
}
static string Method()
{
Log.Error("The Message");
return "Result";
}
Results in:
{
target: Result,
log: {
Error: The Message
}
}

