/by-ignoring

Specify how complex types are logged to Serilog by excluding individual properties.

Primary LanguageC#Apache License 2.0Apache-2.0

Destructurama.ByIgnoring

License

codecov Nuget Nuget

GitHub Release Date GitHub commits since latest release (by date) Size

GitHub contributors Activity Activity Activity

Run unit tests Publish preview to GitHub registry Publish release to Nuget registry CodeQL analysis

Specify how complex types are logged to Serilog by excluding individual properties.

Installation

Install from NuGet:

Install-Package Destructurama.ByIgnoring

Usage

Mark properties to ignore on target types:

Log.Logger = new LoggerConfiguration()
    .Destructure.ByIgnoringProperties<User>(u => u.Password)
    // Other logger configuration
    .CreateLogger()

Mark properties to ignore on assignable types:

Log.Logger = new LoggerConfiguration()
    .Destructure.ByIgnoringPropertiesOfTypeAssignableTo<User>(u => u.Password)
    // Other logger configuration
    .CreateLogger()

When these types are destructured, all instance (that is not static) properties except the specified ones will be passed through:

Log.Information("Logged on {@User}", new User { Username = "nick", Password = "This is ignored" });

// Prints `Logged on User { Username: "nick"  }`

Benchmarks

The results are available here.