초기커밋
This commit is contained in:
55
ServerCore/Log/CloudWatchLog.cs
Normal file
55
ServerCore/Log/CloudWatchLog.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Amazon.Runtime;
|
||||
|
||||
|
||||
using NLog;
|
||||
using NLog.AWS.Logger;
|
||||
using NLog.Config;
|
||||
using NLog.Layouts;
|
||||
|
||||
|
||||
namespace ServerCore;
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user