Files
caliverse_server/ServerCore/Log/CloudWatchLog.cs
2025-11-28 16:54:56 +09:00

60 lines
1.5 KiB
C#

using Amazon.Runtime;
using NLog;
using NLog.AWS.Logger;
using NLog.Config;
using NLog.Layouts;
namespace ServerCore;
// HANDOVER: CloudWatch Log 설정을 제공 한다
public static class CloudWatchLog
{
private static bool m_is_opened = true;
public static bool setup( string? logGroup = null, string? logNamePattern = null, string? logLevel = null
, string? awsRegion = null, string? awsAccessKey = null, string? awsSecretKey = null
, Layout? layout = null )
{
if ( logGroup == string.Empty ||
logNamePattern == string.Empty ||
logLevel == string.Empty ||
awsRegion == string.Empty ||
awsAccessKey == string.Empty ||
awsSecretKey == string.Empty )
{
return false;
}
var current_config = LogManager.Configuration;
if(null == current_config)
{
return false;
}
var aws_target = new AWSTarget()
{
LogGroup = logGroup,
Region = awsRegion,
Credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey),
Layout = layout
};
var newRule = new LoggingRule(logNamePattern, LogLevel.FromString(logLevel), aws_target);
current_config.LoggingRules.Add(newRule);
LogManager.ReconfigExistingLoggers();
return true;
}
public static void setClosed() => m_is_opened = false;
public static bool isOpened() => m_is_opened;
}