Created
November 9, 2015 21:05
-
-
Save dimitrispaxinos/5192465d609f472ce502 to your computer and use it in GitHub Desktop.
Serilog: Add Context using ILogEventEnricher implementations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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