Skip to content

Instantly share code, notes, and snippets.

@dimitrispaxinos
Created November 9, 2015 21:05
Show Gist options
  • Select an option

  • Save dimitrispaxinos/5192465d609f472ce502 to your computer and use it in GitHub Desktop.

Select an option

Save dimitrispaxinos/5192465d609f472ce502 to your computer and use it in GitHub Desktop.
Serilog: Add Context using ILogEventEnricher implementations
public class UserLogEventEnricher : ILogEventEnricher
{
private readonly IUser _user;
public UserLogEventEnricher(IUser user)
{
_user = user;
}
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Username", _user.Username));
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ComputerName", _user.Lab));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment