61 lines
1.1 KiB
C#
61 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using NLog;
|
|
using NLog.Fluent;
|
|
|
|
|
|
using ServerCore; using ServerBase;
|
|
|
|
|
|
namespace ServerBase;
|
|
|
|
public class NLogAppender : IAppender
|
|
{
|
|
private readonly NLog.Logger m_logger = NLog.LogManager.GetLogger("BusinessLogger");
|
|
|
|
public NLogAppender(string xmlCofigFilePath = "")
|
|
{
|
|
if(true == xmlCofigFilePath.isNullOrWhiteSpace())
|
|
{
|
|
return;
|
|
}
|
|
|
|
reconfigureXML(xmlCofigFilePath);
|
|
}
|
|
|
|
public bool reconfigureXML(string xmlCofigFilePath)
|
|
{
|
|
var to_reload_configure = new NLog.Config.XmlLoggingConfiguration(xmlCofigFilePath);
|
|
if(null == to_reload_configure)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
LogManager.Configuration = to_reload_configure;
|
|
LogManager.ReconfigExistingLoggers();
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool isLoadedConfigXML()
|
|
{
|
|
if(null == LogManager.Configuration)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override void write(IFormatter logFormatter, BusinessLog log)
|
|
{
|
|
m_logger?.Info(logFormatter.toLogString(log));
|
|
}
|
|
}
|