[操作影片]
[分解教學]
1、使用nuget安裝log4net
2、確認log4net有進到參考裡面
3、startup.cs 設定
加入
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]
4、webconfig 設定
加入
<configSections>
<!-- Add log4net config section-->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs\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>
<logger name="NHibernate">
<level value="WARN" />
</logger>
<logger name="NHibernate.SQL">
<level value="DEBUG" />
</logger>
</log4net>
5、controller 設定
readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
6、對DB操作以後,再度檢視log.txt 檔案內容觀察變化
留言列表