This package makes it possible to manipulate how objects are logged to Serilog using attributes.
Install from NuGet:
Install-Package Destructurama.AttributedModify logger configuration:
var log = new LoggerConfiguration()
.Destructure.UsingAttributes()
...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);To prevent destructuring of a type or property at all, apply the [LoggedAsScalar] attribute.