从 Log4Net 配置获取值
我通过扩展 AppenderSkeleton 类实现了自定义 log4net 附加程序。它就像任何人都可以要求的那样简单并且工作完美。
我的问题是我必须对一些值进行硬编码,并且我想将它们从我的代码中删除到附加程序的配置中。由于 log4net 知道它是如何配置的,我认为应该有一种方法可以向 log4net 询问它的配置。
我的 Appender 可能看起来像这样:
<appender name="MyLogAppender" type="xxx.yyy.zzz.MyLogAppender">
<MyProperty1>property</MyProperty1>
<MyProperty2>property</MyProperty2>
<MyProperty3>property</MyProperty3>
</appender>
How to get the value MyProperty1-3 so I can use it inside my Appender?
提前致谢 罗兰德
I have implement a custom log4net appender by extending the AppenderSkeleton-class. It was as simple as anyone could ask for and works perfectly.
My problem is that I had to hardcode a few values and I'd like to remove them from my code to the configuration of the appender. Since log4net knows how it is configured I think there should be a way to ask log4net for it's configuraion.
My appender could look something like this:
<appender name="MyLogAppender" type="xxx.yyy.zzz.MyLogAppender">
<MyProperty1>property</MyProperty1>
<MyProperty2>property</MyProperty2>
<MyProperty3>property</MyProperty3>
</appender>
How to get the value of MyProperty1-3 so I can use it inside my Appender?
Thanks in advance
Roalnd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在一定程度上取决于类型,但对于简单类型,您可以执行以下操作:
定义这样的属性:
您可以按如下方式配置:
这当然适用于 string、bool、int 和 TimeSpan。
注意:如果您的设置需要激活某些逻辑(例如创建计时器),那么您可以在
ActivateOptions
方法中实现它。It depends a bit on the type but for simple types you can do the following:
Define a property like this:
This you can configure as follows:
This certainly works for string, bool, int and TimeSpan.
Note: If your settings requires some logic to be activated (e.g. create a timer) then you can implement this in the
ActivateOptions
method.