0

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.

Jürgen Steinblock
  • 30,746
  • 24
  • 119
  • 189
  • https://github.com/Emudofus/BehaviorIsManaged/blob/master/Librairies/NLog/Conditions/ConditionMethods.cs – Vladimir Oct 08 '13 at 09:17
  • Instead of reading the settings from your nlog config file I would try to change the logger rule at runtime, I hope [this question](http://stackoverflow.com/questions/10302561/reconfiguring-nlog-programmatically) will give you some insight – Ferran Salguero Sep 18 '14 at 09:09

1 Answers1

0

Eventually I just changed my rule to

<logger name="WebServiceLogger" minlevel="Fatal" writeTo="webservice" />

and in my code I just create a logger with this name.

Jürgen Steinblock
  • 30,746
  • 24
  • 119
  • 189