Reputation: 1538
I have an endpoint /healthcheck for checking if the application is working or not. The other service will call this endpoint for each 5 seconds.
The problem is this is causing lots of log data for /healthcheck requests. Is there any way to configure Nlog to disable logging for specific route on ASP.NET Core?
Thank you in advance.
Upvotes: 1
Views: 1916
Reputation: 477
You can use NLog Filters for that, check this
I made a filter programmatically, to to log everything (without Critical level) and ignore routes that contain "SignalR" word:
// define a rule for non-exceptions
var nonExceptionsRule = new LoggingRule("*", LogLevel.Trace, LogLevel.Error, myTarget)
{
Final = true,
DefaultFilterResult = FilterResult.LogFinal
};
nonExceptionsRule.Filters.Add(new ConditionBasedFilter
{
Condition = "contains('${aspnet-Request-Url}','SignalR')",
Action = FilterResult.IgnoreFinal
});
You may not specify any levels in your filter, so that it will be for all levels:
var nonExceptionsRule = new LoggingRule("*", myTarget)
{
Final = true,
DefaultFilterResult = FilterResult.LogFinal
};
Upvotes: 1