由于项目中使用了其他第三方插件,不允许将配置写在app.config中 我将配置写在log4net。config中却不能记录日志 到底是何原因
在 AssemblyInfo.cs是这样写的
[assembly:log4net.Config.DOMConfigurator(ConfigFile="log4net",Watch=true)]
log4net。config内容
1<log4net debug="false">
2 <appender name="LogFileAppender" type="log4net.Appender.FileAppender" >
3 <param name="File" value="c:\Applog.txt" />
4 <param name="datePattern" value="yyyy-MM-dd HH:mm" />
5 <param name="AppendToFile" value="true" />
6 <layout type="log4net.Layout.PatternLayout">
7 <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
8 </layout>
9 </appender>
10 <appender name="HttpTraceAppender" type="log4net.Appender.ASPNetTraceAppender" >
11 <layout type="log4net.Layout.PatternLayout">
12 <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
13 </layout>
14 </appender>
15 <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
16 <layout type="log4net.Layout.PatternLayout">
17 <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
18 </layout>
19 </appender>
20 <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
21 <param name="File" value="C:\Log.txt" />
22 <param name="AppendToFile" value="true" />
23 <param name="MaxSizeRollBackups" value="10" />
24 <param name="MaximumFileSize" value="5MB" />
25 <param name="RollingStyle" value="Size" />
26 <param name="StaticLogFileName" value="true" />
27 <layout type="log4net.Layout.PatternLayout">
28 <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
29 </layout>
30 </appender>
31 <root>
32 <level value="DEBUG" />
33 <appender-ref ref="LogFileAppender" />
34 </root>
35</log4net>
用下面的代码,attribute没有用的。
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
private static void Main()
{
var file = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config");
XmlConfigurator.ConfigureAndWatch(file);
var servicesToRun = new ServiceBase[]
{
new TinyRadiusService()
};
ServiceBase.Run(servicesToRun);
}
}
在 AssemblyInfo.cs 应该这样写的
[assembly:log4net.Config.DOMConfigurator(ConfigFile="log4net.config",Watch=true)]
ConfigFile是log4net配置信息的文件路径名(包含后置名)
不可以
不可以呀大哥