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
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