好了,现在我知道如何编写自定义layoutRender传递价值NLOG定制LayoutRenderer
- 写一个类MylayoutRender继承LayoutRenderer,在课堂上,
- 覆盖追加方法
注册自定义layoutRenderer启动时
ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("application", typeof(MyLayoutRenderer));
curently,我读了配置
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
var product = CommonMethods.ReadConfig("product");
builder.Append(product);
}
价值如何动态设置的值?
看起来像我所做的一样:从配置文件(CommonMethods.ReadConfig(“product”);)读取 – prime23 2012-03-01 06:04:24
你想做一些不同的事情吗?我读过这个问题的方式,我想你可能希望能够配置LayoutRenderer,以便从配置文件中读取任何值。通过将值名称指定为NLog.config文件中的LayoutRenderer的参数来实现这一点的LayoutRenderer的想法就是这样做的。你还在找别的东西吗?可能有更好的方法来做你想做的事。 – wageoghe 2012-03-01 14:37:48
对于迟到回复感到抱歉。我想要做的是设置Append方法的值,但不给参数layoutRender。但由于我的自定义layoutRender(应用程序名称)是一个常量,我只是硬编码到SQL插入NLog.config中。再次感谢你。 – prime23 2012-03-05 06:25:18