Last active
August 29, 2015 14:00
-
-
Save yicone/54a6b0fd844c77fec6c9 to your computer and use it in GitHub Desktop.
使用log4net 历经纠结, 却也**从没有享受过纠结的好处**!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration> | |
<!--添加log4net自定义节点--> | |
<configSections> | |
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/> | |
</configSections> | |
<log4net> | |
<appender name="FileAppender" type="log4net.Appender.FileAppender"> | |
<!--文件路径--> | |
<file value="D:\logs\log.txt"/> | |
<rollingStyle value="Date" /> | |
<appendToFile value="true"/> | |
<!--显示格式--> | |
<layout type="log4net.Layout.PatternLayout"> | |
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/> | |
</layout> | |
</appender> | |
<root> | |
<appender-ref ref="FileAppender"/> | |
</root> | |
</log4net> | |
</configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using log4net; | |
// todo: change namespace name | |
namespace Ibags.API.App_Start | |
{ | |
public class Logger | |
{ | |
private static ILog instance; | |
public static ILog Instance() | |
{ | |
if (instance == null) | |
{ | |
instance = log4net.LogManager.GetLogger( | |
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType | |
); | |
} | |
instance.Info("Logger has a new instance. "); | |
return instance; | |
} | |
private Logger() { } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment