<nlog xmlns="http:www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http:www.w3.org/2001/XMLSchema-instance"
throwExceptions="true">
<targets>
<target name="aws" type="AWSTarget" logGroup="NLog.ConfigPOC"
region="us-east-1" />
<target name="logfile" xsi:type="Console" layout="${callsite} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="aws" />
</rules>
<extensions>
<add assembly="NLog.AWS.Logger" />
</extensions>
</nlog>
public class NLogWrapper
{
private readonly Logger logger;
public NLogWrapper()
{
Configure();
}
public void Configure()
{
var config = new LoggingConfiguration();
string accessKey = "put your access key here";
string secretKey = "put your secret key here";
var awsTarget = new AWSTarget()
{
LogGroup = "Log.ConfigPOC",
Region = "us-east-1",
Credentials = new Amazon.Runtime.BasicAWSCredentials(accessKey,secretKey)
};
config.AddTarget("aws", awsTarget);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, awsTarget));
LogManager.Configuration = config;
}
public void Info(object message)
{
logger.Info(message);
}
public void Error(Exception exception)
{
logger.Error(exception);
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="AWSProfileName" value="test" />
<add key="AWSProfilesLocation" value="C:\credentials.txt" />
</appSettings>
</configuration>
[test] aws_access_key_id = put key here aws_secret_access_key = put key here
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http:www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http:www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="bw"
xsi:type="BufferingWrapper" slidingTimeout="true" bufferSize="100" flushTimeout="60000">
<target name="cwl" xsi:type="CloudWatchLogs" AWSRegion="aws-region" AWSAccessKeyId="access-id" AWSSecretKey="secret-key" LogGroupName="log-group" LogStreamName="log-stream" layout="${longdate} [${threadid}] ${level} ${logger} [${ndc}] - ${message}" />
</target>
</targets>
<rules>
<logger name="*" minLevel="Info" appendTo="bw" />
</rules>
</nlog>
public class NLogWrapper
{
private readonly Logger logger;
public NLogWrapper()
{
logger = LogManager.GetCurrentClassLogger();
}
public void Info(object message)
{
logger.Info(message);
}
public void Error(Exception exception)
{
logger.Error(exception);
}
}
Share this page on
6
People Like(s) This Page
Permalink
comments powered by Disqus