Sic.Framework-Nanjing-Baishi/MECF.Framework.Common/Aitex/Core/RT/Log/LogWriter.cs

55 lines
1.1 KiB
C#

using System;
using System.Reflection;
using log4net.Core;
namespace Aitex.Core.RT.Log
{
internal class LogWriter
{
private static readonly Type ThisDeclaringType = typeof(LogWriter);
private readonly ILogger defaultLogger;
public LogWriter()
{
defaultLogger = LoggerManager.GetLogger(Assembly.GetExecutingAssembly(), "CommonLogger");
}
private string FormatLogString(LogItem logItem)
{
string empty = string.Empty;
string result = logItem.msg;
try
{
string fileName = logItem.sf.GetFileName();
if (fileName != null)
{
empty = fileName.Substring(fileName.LastIndexOf('\\') + 1);
}
}
catch (Exception)
{
empty = string.Empty;
}
try
{
result = string.Format("{0}\t{1}\t{2} ", logItem.dt.ToString("yyyy/MM/dd HH:mm:ss.fff"), logItem.lv.Name, logItem.msg);
}
catch (Exception)
{
}
return result;
}
public string Write(LogItem logItem)
{
string text = FormatLogString(logItem);
if (defaultLogger.IsEnabledFor(logItem.lv))
{
defaultLogger.Log(typeof(LogWriter), logItem.lv, text, logItem.ex);
}
return text;
}
}
}