LogHelper.cs
1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using log4net;
using log4net.Config;
using log4net.Repository;
using System.IO;
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
namespace Infrastructure
{
public class LogHelper
{
private static ILog logger = null;
public static void LogError(string logstr)
{
if (InitLog4net())
logger.Error(logstr);
}
private static object objlock = new object();//初始化log用的锁
private static bool InitLog4net()
{
if (logger != null)
return true;
lock (objlock)
{
if (logger == null)
{
ILoggerRepository repository = LogManager.CreateRepository("NETCoreRepository");
XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
logger = LogManager.GetLogger(repository.Name, "NETCorelog4net");
return true;
}
}
return false;
}
}
}