You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using log4net;
using log4net.Config;
namespace Estsh.Core.Util
{
public class LogHelper
{
/// <summary>
/// ILog实例
/// </summary>
private static ILog logger;
/// <summary>
/// 构造函数
/// </summary>
static LogHelper()
{
if (logger == null)
{
var repository = LogManager.CreateRepository("NETCoreRepository");
var path = Directory.GetCurrentDirectory() + "/log4net.config";
//读取配置信息
XmlConfigurator.Configure(repository, new FileInfo(path));
logger = LogManager.GetLogger(repository.Name, "InfoLogger");
}
}
/// <summary>
/// 普通日志
/// </summary>
/// <param name="message">摘要</param>
/// <param name="exception">异常</param>
public static void Info(string message, Exception exception = null)
{
if (logger != null)
{
if (exception == null)
{
logger.Info(message);
}
else
{
logger.Info(message, exception);
}
}
}
/// <summary>
/// 警告日志
/// </summary>
/// <param name="message">摘要</param>
/// <param name="exception">异常</param>
public static void Warn(string message, Exception exception = null)
{
//判断审计日志记录开关是否开启
if (logger != null)
{
if (exception == null)
{
logger.Warn(message);
}
else
{
logger.Warn(message, exception);
}
}
}
/// <summary>
/// 错误日志
/// </summary>
/// <param name="message">摘要</param>
/// <param name="exception">异常</param>
public static void Error(string message, Exception exception = null)
{
//判断审计日志记录开关是否开启
if (logger != null)
{
if (exception == null)
{
logger.Error(message);
}
else
{
logger.Error(message, exception);
}
}
}
/// <summary>
/// Debug日志
/// </summary>
/// <param name="message">摘要</param>
/// <param name="exception">异常</param>
public static void Debug(string message, Exception exception = null)
{
//判断审计日志记录开关是否开启
if (logger != null)
{
if (exception == null)
{
logger.Debug(message);
}
else
{
logger.Debug(message, exception);
}
}
}
}
}