1. 程式人生 > >C# Log4j 動態配置日誌目錄

C# Log4j 動態配置日誌目錄

1、配置log4net.config

<appender name="BaseLog" type="log4net.Appender.RollingFileAppender">
<file value="LogFiles\Base\" />
</appender>
<logger name="MyLog.Base.Log">
<level value="DEBUG" />
<appender-ref ref="BaseLog" />
</logger>

2、程式碼中動態決定使用哪個配置

log4net.Config.XmlConfigurator.Configure(new Uri(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log4net.config"));
public static readonly ILog BaseLogger = LogManager.GetLogger("MyLog.Base.Log");