Skip to content

nblumhardt/attributed

 
 

Repository files navigation

Destructurama.Attributed Build status

This package makes it possible to manipulate how objects are logged to Serilog using attributes.

Enabling the module:

Install from NuGet:

Install-Package Destructurama.Attributed

Modify logger configuration:

var log = new LoggerConfiguration()
  .Destructure.UsingAttributes()
  ...

Ignoring a property

Apply the NotLogged attribute:

public class LoginCommand
{
  public string Username { get; set; }

  [NotLogged]
  public string Password { get; set; }
}

When the object is passed using {@...} syntax the attributes will be consulted.

var command = new LoginCommand { Username = "logged", Password = "not logged" };
log.Information("Logging in {@Command}", command);

Treating types and properties as scalars

To prevent destructuring of a type or property at all, apply the [LoggedAsScalar] attribute.

About

Use attributes to control how complex types are logged to Serilog.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages