【发布时间】:2013-10-15 00:51:01
【问题描述】:
我正在使用带有 nlog.config 文件的 nlog。
现在我有一个将未处理的异常记录到 Web 服务的目标
<target xsi:type="WebService" name="webservice"
url="http://server.tld/services/errorreporting/"
methodName=""
namespace=""
protocol="HttpPost"
>
....
</target>
还有一条规则:
<logger name="*" minlevel="Fatal" writeTo="webservice" />
现在我不允许用户决定是否要使用此功能。
该应用程序是一个 winforms 应用程序,用户会看到一个未处理异常的对话框。现在我想添加一个errorreporting 复选框。只有选中它,我才想登录我的网络服务。
我的想法是为我的规则使用自定义条件的过滤器。 nlog docs 声明:
New condition functions are easy to add; just create an ordinary function and mark it with the [ConditionMethod] attribute.
所以我可以写一个函数
public static bool ErrorReportingEnabled()
{
return Properties.Settings.Default.ErrorReportingEnabled;
}
但我没有找到任何关于如何在我的过滤器中定义此函数的参考。
【问题讨论】:
-
我不会从您的 nlog 配置文件中读取设置,而是尝试在运行时更改记录器规则,希望 this question 能给您一些见解