I had a similar issue, but in my case I wanted to filter based on the source that was logging info. Some Microsoft logs were just not useful, so I wanted to include only the ones that were. 754 is probably a better overall solution, but my workaround for this in ASP.Net Core is to use a filter like so:
----------------
new LoggerConfiguration()
.Filter.ByExcluding(Serilog.Filters.Matching.WithProperty<Serilog.Events.ScalarValue>("SourceContext", scalar =>
{
string sourceContext = scalar.Value as string;
if (!string.IsNullOrEmpty(sourceContext))
{
if (sourceContext.StartsWith("Microsoft.AspNetCore."))
{
// We can have other conditionals here or use a dictionary to determine if we have a match
// Useful mappings:
if (sourceContext == "Microsoft.AspNetCore.Hosting.Internal.WebHost"
|| sourceContext == "Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker")
{
return false;
}
return true;
}
}
return false;
}))
--------------------
You could also pass your own lambda and not use the scalar helper if you want the level, as well; it will pass a LogEvent to you and and you can choose whether or not to log it based on the SourceContext. Not sure if that is set in MVC 5, though.
-Ryan