using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class LogHelper
|
{
|
#region Info
|
|
//这里的 loginfo 和 log4net.config 里的名字要一样
|
private static readonly log4net.ILog _loginfo =LogConfig.GetLogger("Info");
|
|
/// <summary>
|
/// 写入信息日志
|
/// </summary>
|
public static void Info(string info)
|
{
|
if (_loginfo.IsInfoEnabled)
|
{
|
_loginfo.Info(info);
|
}
|
}
|
|
/// <summary>
|
/// 写入信息日志
|
/// </summary>
|
public static void InfoFormat(string format, params object[] args)
|
{
|
if (_loginfo.IsInfoEnabled)
|
{
|
_loginfo.InfoFormat(format, args);
|
}
|
}
|
|
#endregion
|
|
#region Debug
|
|
//这里的 logdebug 和 log4net.config 里的名字要一样
|
private static readonly log4net.ILog _logdebug = LogConfig.GetLogger("Debug");
|
|
/// <summary>
|
/// 写入调试日志
|
/// </summary>
|
public static void Debug(string info)
|
{
|
if (_logdebug.IsInfoEnabled)
|
{
|
_logdebug.Debug(info);
|
}
|
}
|
|
/// <summary>
|
/// 写入调试日志
|
/// </summary>
|
public static void DebugFormat(string format, params object[] args)
|
{
|
if (_logdebug.IsInfoEnabled)
|
{
|
_logdebug.DebugFormat(format, args);
|
}
|
}
|
|
#endregion
|
|
#region Error
|
private static readonly log4net.ILog _logerror = LogConfig.GetLogger("Error");
|
|
/// <summary>
|
/// 写入错误日志
|
/// </summary>
|
public static void Error(string info, Exception ex = null)
|
{
|
if (_logerror.IsErrorEnabled)
|
{
|
if (ex == null)
|
_logerror.Error(info);
|
else
|
_logerror.Error(info, ex);
|
}
|
}
|
|
/// <summary>
|
/// 写入错误日志
|
/// </summary>
|
public static void ErrorFormat(string format, params object[] args)
|
{
|
if (_logerror.IsErrorEnabled)
|
{
|
_logerror.ErrorFormat(format, args);
|
}
|
}
|
|
/// <summary>
|
/// 写入错误日志
|
/// </summary>
|
public static void Error(string info, int line, Exception ex = null)
|
{
|
if (_logerror.IsErrorEnabled)
|
{
|
if (ex == null)
|
_logerror.Error(info + " 在代码第" + line);
|
else
|
_logerror.Error(info + " 在代码第" + line, ex);
|
}
|
}
|
#endregion
|
|
#region 自定义
|
|
/// <summary>
|
/// 自定义
|
/// </summary>
|
public static void Custom(string name, string msg)
|
{
|
var log = LogConfig.GetLogger(name);
|
if (log.IsInfoEnabled)
|
{
|
log.Info(msg);
|
}
|
}
|
|
/// <summary>
|
/// 自定义
|
/// </summary>
|
public static void CustomFormat(string name, string format, params object[] args)
|
{
|
var log = LogConfig.GetLogger(name);
|
if (log.IsInfoEnabled)
|
{
|
log.InfoFormat(format,args);
|
}
|
}
|
|
|
#endregion
|
|
}
|
}
|