我有以下
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="D:\projects\Code\log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
对于发布我想更改文件路径,但它似乎没有工作,这是我在我的web.release.config
<log4net xdt:Transform="RemoveAttributes(debug)" >
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="c:\temp.txt" xdt:Transform="Replace" xdt:Locator="Match(value)" />
</appender>
</log4net>
这是结果
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="D:\projects\Code\log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
它删除调试部分,但不修复文件路径。
答案 0 :(得分:0)
我认为你应该尝试这样的事情。
`<log4net>
<appender name="InfoRollingLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
<file type="log4net.Util.PatternString" value="%property{ProgramDataPath}\errorLog" />
...
`
初始化记录器时,
var path = ConfigurationManager.AppSettings["LogLocation"];
// Directory.SetCurrentDirectory(path);
GlobalContext.Properties["ProgramDataPath"] = path;
XmlConfigurator.Configure();
log = LogManager.GetLogger(typeof(Logger));
最后只需更改LogLocation中的值。 我希望这可以帮到你。感谢