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