I am using nlog with the nlog.config
file.
Now I have a target that logs unhandled exceptions to a webservice
<target xsi:type="WebService" name="webservice"
url="http://server.tld/services/errorreporting/"
methodName=""
namespace=""
protocol="HttpPost"
>
....
</target>
And a rule:
<logger name="*" minlevel="Fatal" writeTo="webservice" />
Now I wan't to allow the user to decide if he wants to use this feature.
The application is a winforms app and the user sees a dialog for unhandled exceptions. Now I want to add an errorreporting
checkbox. Only if it is checked, I want to log to my webservice.
My idea is to use a filter for my rule with a custom condition. The nlog docs claim:
New condition functions are easy to add; just create an ordinary function and mark it with the [ConditionMethod] attribute.
So I could write a function
public static bool ErrorReportingEnabled()
{
return Properties.Settings.Default.ErrorReportingEnabled;
}
but I don't find any reference on how to define this function in my filter.