244 lines
5.5 KiB
C#
244 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Amazon.OpenSearchService.Model.Internal.MarshallTransformations;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
|
|
using ServerCore; using ServerBase;
|
|
|
|
|
|
using LOG_ACTION_TYPE = System.String;
|
|
using LOG_DOMAIN_TYPE = System.String;
|
|
|
|
|
|
namespace ServerBase;
|
|
|
|
public enum LogTransToOutputType
|
|
{
|
|
TransToMultyLine = 0, // Body 갯수대로 로그 출력
|
|
TransToSingleLine = 1, // 한개의 Body로 로그 출력
|
|
}
|
|
|
|
//===================================================================================
|
|
// 로그 액션
|
|
//===================================================================================
|
|
|
|
public partial class LogAction
|
|
{
|
|
private readonly LOG_ACTION_TYPE m_log_action_type = string.Empty;
|
|
private Guid m_tran_id = Guid.Empty;
|
|
|
|
public LogAction(LOG_ACTION_TYPE logActionType)
|
|
{
|
|
m_log_action_type = logActionType;
|
|
m_tran_id = Guid.NewGuid();
|
|
}
|
|
|
|
public LogAction(LOG_ACTION_TYPE logActionType, Guid tranId)
|
|
{
|
|
m_log_action_type = logActionType;
|
|
m_tran_id = tranId;
|
|
}
|
|
|
|
}//LogAction
|
|
|
|
|
|
//===================================================================================
|
|
// 로그를 발생 시킨다
|
|
//===================================================================================
|
|
|
|
public abstract partial class ILogInvoker
|
|
{
|
|
private LogAction? m_log_action_nullable;
|
|
private readonly LOG_DOMAIN_TYPE m_log_domain_type = string.Empty;
|
|
|
|
public ILogInvoker()
|
|
{
|
|
}
|
|
|
|
public ILogInvoker(LOG_DOMAIN_TYPE logDomainType)
|
|
{
|
|
m_log_domain_type = logDomainType;
|
|
}
|
|
|
|
public ILogInvoker(LOG_DOMAIN_TYPE logDomainType, LogAction logAction)
|
|
{
|
|
m_log_action_nullable = logAction;
|
|
m_log_domain_type = logDomainType;
|
|
}
|
|
|
|
public ServerErrorCode alloc(ILogActor logActor, out BusinessLog? businessLog)
|
|
{
|
|
ArgumentNullReferenceCheckHelper.throwIfNull(logActor, () => $"logActor is null !!!");
|
|
|
|
businessLog = null;
|
|
|
|
if (null == m_log_action_nullable)
|
|
{
|
|
return ServerErrorCode.LogActionIsNull;
|
|
}
|
|
|
|
var header = new BusinessLog.LogHeader(m_log_action_nullable.getTranId().ToString(), logActor);
|
|
var body = new BusinessLog.LogBody(m_log_action_nullable.getLogActionType());
|
|
{
|
|
fillup(ref body);
|
|
}
|
|
|
|
businessLog = new BusinessLog(header, body);
|
|
|
|
return ServerErrorCode.Success;
|
|
}
|
|
|
|
public static ServerErrorCode alloc( LOG_ACTION_TYPE logActionType, Guid tran
|
|
, ILogActor actorLog, List<ILogInvoker> invokers
|
|
, LogTransToOutputType outputType, ref List<BusinessLog> outLogs )
|
|
{
|
|
if (logActionType.isNullOrWhiteSpace())
|
|
{
|
|
return ServerErrorCode.LogActionTypeInvalid;
|
|
}
|
|
|
|
var header = new BusinessLog.LogHeader(tran.ToString(), actorLog);
|
|
switch (outputType)
|
|
{
|
|
case LogTransToOutputType.TransToMultyLine:
|
|
{
|
|
foreach (var each in invokers)
|
|
{
|
|
var body = new BusinessLog.LogBody(logActionType);
|
|
{
|
|
if (false == each.hasLog())
|
|
{
|
|
continue;
|
|
}
|
|
each.fillup(ref body);
|
|
|
|
outLogs.Add(new BusinessLog(header, body));
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case LogTransToOutputType.TransToSingleLine:
|
|
{
|
|
var body = new BusinessLog.LogBody(logActionType);
|
|
{
|
|
foreach (var each in invokers)
|
|
{
|
|
if (false == each.hasLog())
|
|
{
|
|
continue;
|
|
}
|
|
each.fillup(ref body);
|
|
}
|
|
outLogs.Add(new BusinessLog(header, body));
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
return ServerErrorCode.Success;
|
|
}
|
|
|
|
protected abstract void fillup(ref BusinessLog.LogBody body);
|
|
|
|
// 로그가 들어 있는지 검사한다.
|
|
public abstract bool hasLog();
|
|
|
|
public virtual string toBasicString()
|
|
{
|
|
return $"LogInvoker:{this.getTypeName()}";
|
|
}
|
|
|
|
//===================================================================================
|
|
// 사용자 정의 로그 정보 추상 클래스 이다.
|
|
//===================================================================================
|
|
public abstract class IInfo
|
|
{
|
|
[JsonProperty(Order = -2)]
|
|
private readonly LOG_DOMAIN_TYPE Domain = string.Empty;
|
|
|
|
// ILogInvoker 에 의해 생성될 경우 로그 정보 컨테이너에 적재되고
|
|
// 로그 정보를 Json 기반으로 직렬화 한다.
|
|
public IInfo(ILogInvoker parent)
|
|
{
|
|
Domain = parent.m_log_domain_type;
|
|
}
|
|
|
|
// 로그 정보 전달 객체로 활용 된다 !!!
|
|
public IInfo()
|
|
{
|
|
}
|
|
}//IInfo
|
|
}//ILogInvoker
|
|
|
|
|
|
public class BusinessLog
|
|
{
|
|
[JsonProperty]
|
|
private readonly LogHeader Header;
|
|
[JsonProperty]
|
|
private readonly LogBody Body;
|
|
|
|
public BusinessLog(LogHeader header, LogBody body)
|
|
{
|
|
Header = header;
|
|
Body = body;
|
|
}
|
|
|
|
public bool hasLog()
|
|
{
|
|
return Header != null && Body != null && Header.hasLog() && Body.hasLog();
|
|
}
|
|
|
|
public class LogHeader
|
|
{
|
|
[JsonProperty]
|
|
private readonly string TranId = string.Empty;
|
|
[JsonProperty]
|
|
private readonly ILogActor Actor;
|
|
|
|
public LogHeader(string tran_id, ILogActor actor_log)
|
|
{
|
|
TranId = tran_id;
|
|
Actor = actor_log;
|
|
}
|
|
|
|
public bool hasLog()
|
|
{
|
|
return Actor != null;
|
|
}
|
|
}
|
|
|
|
public class LogBody
|
|
{
|
|
[JsonProperty]
|
|
private readonly LOG_ACTION_TYPE Action = string.Empty;
|
|
[JsonProperty]
|
|
private readonly List<ILogInvoker.IInfo> Infos = new List<ILogInvoker.IInfo>();
|
|
|
|
public LogBody(LOG_ACTION_TYPE action)
|
|
{
|
|
Action = action;
|
|
}
|
|
|
|
public bool hasLog(bool allow_empty = false)
|
|
{
|
|
if (Action.isNullOrWhiteSpace())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return allow_empty ? true : Infos.Count != 0;
|
|
}
|
|
|
|
public void append(ILogInvoker.IInfo info)
|
|
{
|
|
Infos.Add(info);
|
|
}
|
|
}
|
|
}
|