93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
|
|
|
|
using ServerCore; using ServerBase;
|
|
|
|
|
|
namespace ServerBase;
|
|
|
|
//========================================================================================================
|
|
// 비즈니스 로그 처리자
|
|
//
|
|
// 운영 담당 부서와 사업 담당 부서에서 필요로 하는 주요 속성들 정의 하여
|
|
// 필요로 하는 데이터 포멧에 맞게 출력 한다.
|
|
//========================================================================================================
|
|
public static class BusinessLogger
|
|
{
|
|
private static IAppender? m_appender;
|
|
private static IFormatter? m_formatter;
|
|
private static LogTransToOutputType m_output_type = LogTransToOutputType.TransToSingleLine;
|
|
|
|
//==========================================================================
|
|
// appender를 셋팅한다.
|
|
//==========================================================================
|
|
public static void setup(IAppender appender, IFormatter logFormatter, LogTransToOutputType outputType)
|
|
{
|
|
m_appender = appender;
|
|
m_formatter = logFormatter;
|
|
m_output_type = outputType;
|
|
}
|
|
|
|
|
|
//==========================================================================
|
|
// 단일 로그를 수집 한다.
|
|
//==========================================================================
|
|
public static ServerErrorCode collectLog(IWithLogActor actor, ILogInvoker invoker)
|
|
{
|
|
ArgumentNullReferenceCheckHelper.throwIfNull(actor, () => $"actor is null !!!");
|
|
ArgumentNullReferenceCheckHelper.throwIfNull(invoker, () => $"invoker is null !!!");
|
|
|
|
if (m_appender == null)
|
|
{
|
|
return ServerErrorCode.LogAppenderIsNull;
|
|
}
|
|
|
|
if(m_formatter == null)
|
|
{
|
|
return ServerErrorCode.LogAppenderIsNull;
|
|
}
|
|
|
|
if(true == invoker.hasLog())
|
|
{
|
|
var is_success = invoker.alloc(actor.toLogActor(), out var log);
|
|
if (is_success.isSuccess() && log != null)
|
|
{
|
|
m_appender.write(m_formatter, log);
|
|
}
|
|
}
|
|
|
|
return ServerErrorCode.Success;
|
|
}
|
|
|
|
//==========================================================================
|
|
// 복합 로그를 수집 한다.
|
|
//==========================================================================
|
|
public static ServerErrorCode collectLogs(LogAction logAction, IWithLogActor actor, List<ILogInvoker> invokers)
|
|
{
|
|
if (m_appender == null)
|
|
{
|
|
return ServerErrorCode.LogAppenderIsNull;
|
|
}
|
|
|
|
if (m_formatter == null)
|
|
{
|
|
return ServerErrorCode.LogFormatterIsNull;
|
|
}
|
|
|
|
List<BusinessLog> logs = new List<BusinessLog>();
|
|
var result_code = ILogInvoker.alloc(logAction.getLogActionType(), logAction.getTranId(), actor.toLogActor(), invokers, m_output_type, ref logs);
|
|
if(result_code.isFail())
|
|
{
|
|
return result_code;
|
|
}
|
|
|
|
foreach (var log in logs)
|
|
{
|
|
if (log != null && log.hasLog())
|
|
{
|
|
m_appender.write(m_formatter, log);
|
|
}
|
|
}
|
|
|
|
return ServerErrorCode.Success;
|
|
}
|
|
} |