Extends Verify to allow verification of Serilog bits.
See Milestones for release notes.
Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.
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();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
}));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.
[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
}
}
