Skip to content

Instantly share code, notes, and snippets.

@yicone
Last active August 29, 2015 14:00
Show Gist options
  • Save yicone/54a6b0fd844c77fec6c9 to your computer and use it in GitHub Desktop.
Save yicone/54a6b0fd844c77fec6c9 to your computer and use it in GitHub Desktop.
使用log4net 历经纠结, 却也**从没有享受过纠结的好处**!
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
<?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>
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