Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MahdiKarimipour/08dbbc2c6ea543808bce2894b02c8979 to your computer and use it in GitHub Desktop.
Save MahdiKarimipour/08dbbc2c6ea543808bce2894b02c8979 to your computer and use it in GitHub Desktop.
ILogger Implementation
public void Log<TState>(
Microsoft.Extensions.Logging.LogLevel logLevel,
EventId eventId,
TState state,
Exception exception,
Func<TState, Exception, string> formatter)
{
if (!IsEnabled(logLevel))
{
return;
}
if (nloggerConfiguration.EventId == 0 || nloggerConfiguration.EventId == eventId.Id)
{
var logEventInfo = new LogEventInfo(GetLogLevel(logLevel), name, $"{formatter(state, exception)}");
if (!exception.IsEmpty())
{
logEventInfo.Exception = exception;
}
logger
.WithProperty("UserId", userContext.UserId)
.WithProperty("Environment", Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"))
.WithProperty("Channel", userContext.Channel)
.WithProperty("UserAgent", requestContext.UserAgent)
.WithProperty("CorrelationId", requestContext.CorrelationId)
.WithProperty("EventId", eventId.Id)
.Log(logEventInfo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment