using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
|
namespace IStation
|
{
|
public class LogHelper
|
{
|
public static void Initial()
|
{
|
string directory ;
|
if (IStation.DataFolderHelper.IsExeExcute)
|
{
|
directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).FullName;
|
}
|
else
|
{
|
directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
}
|
var configFile = System.IO.Path.Combine(directory, "Config","log4net.config");
|
|
if (System.IO.File.Exists(configFile))
|
{
|
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(configFile));
|
}
|
else
|
{
|
log4net.Config.XmlConfigurator.Configure();
|
}
|
|
logError = log4net.LogManager.GetLogger("IStation.Error");
|
logInfo = log4net.LogManager.GetLogger("IStation.Info");
|
logInfo.Info("初始化成功");
|
}
|
|
#region 错误日志
|
private static log4net.ILog logError = null;
|
public static void WriteError(string msg,Exception ex)
|
{
|
if (logError == null)
|
logError = log4net.LogManager.GetLogger("IStation.Error");
|
logError.Error(msg, ex);
|
}
|
public static void WriteError(string msg ,int line, Exception ex)
|
{
|
if (logError == null)
|
logError = log4net.LogManager.GetLogger("IStation.Error");
|
logError.Error(string.Format("msg:{0}, line:{1}",msg,line), ex);
|
}
|
public static void WriteError(string msg)
|
{
|
if (logError == null)
|
logError = log4net.LogManager.GetLogger("IStation.Error");
|
logError.Error(msg);
|
}
|
public static void Error( Exception ex)
|
{
|
if (logError == null)
|
logError = log4net.LogManager.GetLogger("IStation.Error");
|
logError.Error(ex.Message, ex);
|
}
|
public static void Error(string msg, Exception ex)
|
{
|
if (logError == null)
|
logError = log4net.LogManager.GetLogger("IStation.Error");
|
logError.Error(msg, ex);
|
}
|
public static void Error(string msg, int line, Exception ex)
|
{
|
if (logError == null)
|
logError = log4net.LogManager.GetLogger("IStation.Error");
|
logError.Error(string.Format("msg:{0}, line:{1}", msg, line), ex);
|
}
|
public static void Error(string msg)
|
{
|
if (logError == null)
|
logError = log4net.LogManager.GetLogger("IStation.Error");
|
logError.Error(msg);
|
}
|
#endregion
|
|
#region 正常日志
|
private static log4net.ILog logInfo = null;
|
public static void Info(string info)
|
{
|
if (logInfo == null)
|
logInfo = log4net.LogManager.GetLogger("IStation.Info");
|
if (logInfo != null)
|
{
|
logInfo.Info(info);
|
}
|
}
|
|
#endregion
|
|
|
|
}
|
}
|