using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace AutoCheckSMS.Common
|
{
|
/// <summary>
|
/// 日志服务
|
/// </summary>
|
public class Log4netService
|
{
|
static Log4netService()
|
{
|
string path = AppDomain.CurrentDomain.BaseDirectory + "log4net.config";
|
log4net.Config.XmlConfigurator.Configure(new FileInfo(path));
|
}
|
|
|
public static log4net.ILog GetLog(string logName)
|
{
|
log4net.ILog log = log4net.LogManager.GetLogger(logName);
|
return log;
|
}
|
private static string DefaultLoggerName = "RollingFileLog";
|
private static string ErrLoggerName = "ErrRollingFileLog";
|
|
public static void Debug(string message)
|
{
|
log4net.ILog log = log4net.LogManager.GetLogger(DefaultLoggerName);
|
if (log.IsDebugEnabled)
|
{
|
Console.WriteLine($"{DateTime.Now}-{message}");
|
log.Debug(message);
|
}
|
log = null;
|
}
|
public static void Info(string message)
|
{
|
log4net.ILog log = log4net.LogManager.GetLogger(DefaultLoggerName);
|
if (log.IsInfoEnabled)
|
{
|
Console.WriteLine($"{DateTime.Now}-{message}");
|
log.Info(message);
|
}
|
log = null;
|
}
|
public static void Error(string message)
|
{
|
log4net.ILog log = log4net.LogManager.GetLogger(ErrLoggerName);
|
if (log.IsErrorEnabled)
|
{
|
Console.WriteLine($"{DateTime.Now}-{message}");
|
log.Error(message);
|
}
|
log = null;
|
}
|
public static void Warn(string message)
|
{
|
log4net.ILog log = log4net.LogManager.GetLogger(ErrLoggerName);
|
if (log.IsWarnEnabled)
|
{
|
Console.WriteLine($"{DateTime.Now}-{message}");
|
log.Warn(message);
|
}
|
log = null;
|
}
|
}
|
}
|