How to remove properties from log entries in ASP.Net Core
This can be achieved by plugging an enricher into the logging pipeline:
.Enrich.With(new RemovePropertiesEnricher())
Where:
class RemovePropertiesEnricher : ILogEventEnricher
{
public void Enrich(LogEvent le, ILogEventPropertyFactory lepf)
{
le.RemovePropertyIfPresent("SourceContext");
le.RemovePropertyIfPresent("RequestId");
le.RemovePropertyIfPresent("RequestPath");
}
}
Yes, you can get rid of them. Try to use log template:
_loggerConfiguration.WriteTo.Console(LogLevel.Debug, "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level}] {Message}{NewLine}{Exception}");
In this scenario, you won't see mentioned properties in your output.