遇到了标题所示的问题。baidu google之。未果,csdn上有人问过这个问题但是没有任何回答。
研究了下 记之如下
webconfig中在<configuration></configuration>标签中写入:
Code
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net-net-1.0" />
</configSections>
<log4net>
<logger name="Logger"></logger>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender" >
<param name="File" value="bin\log-file.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}>%n - %m%n" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
AssemblyInfo.cs中加入:
[assembly: log4net.Config.XmlConfigurator (ConfigFile="Web.config",Watch=true)]
示例页面中引用log4net,需要写日志的地方加入如下代码:
log4net.ILog log = log4net.LogManager.GetLogger("Logger");
log.Debug("价格策略异常");
运行在web应用程序的bin下生成日志文件log-file.txt