How can I tell log4net which appender to use from app.config

牧云@^-^@ 提交于 2019-12-07 04:24:59

问题


I had a quick log4net question. How can I specify which appender to use from the app.Config? This particular config file references 2 different appenders. Both are rolling file appenders but they point to different files. Throughout the application log4net is being called and a type is passed into the constructor. like this...

 private static readonly ILog log = LogManager.GetLogger(typeof(Foo));

How does log4net know which appender to choose? Can you map types to specific named appenders? I know there are 5 constructors for GetLogger, can you pass a type and an appender name? I see "repositoryName", not sure what that is. If anyone can point me in the right direction I would greatly appreciate it. I would like a certain set of types to log specifically to one appender.

Thanks for any tips,
~ck in San Diego


回答1:


Use a <logger> element, using the full class name of Foo:

<logger name="full.parent.namespace.Foo">
  <level value="WARN" />
  <appender-ref ref="SomeAppender" />
</logger>

Specify a minimum level and reference to the required output appender to use.

You can also use a single <logger> for all classes in a particular namespace by omitting the class name.

<logger name="full.parent.namespace">
  ....
</logger>


来源:https://stackoverflow.com/questions/3685965/how-can-i-tell-log4net-which-appender-to-use-from-app-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!