我正在ASP Net Core 2.1应用程序中设置NLog 但是它没有在AWS上生成日志,我遵循了文档,做了一些测试,我只能在localhost上生成log.txt,但是对于AWS配置却无法正常工作。难道我做错了什么? 遵循代码:
这是配置NLog
<?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"
throwConfigExceptions="true">
<extensions>
<add assembly="NLog.AWS.Logger" />
</extensions>
<targets>
<target name="aws" type="AWSTarget" logGroup="NLog.ConfigExample" region="us-east-1"/>
<target name="logfile" xsi:type="Console" layout="${callsite} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile,aws" />
</rules>
</nlog>
我这样称呼它:
Program.cs
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using NLog.Web;
using Microsoft.Extensions.Logging;
using System;
using NLog;
using NLog.Config;
using NLog.Targets;
using NLog.AWS.Logger;
namespace API_Coletor_Status
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
ConfigureNLog();
Logger loggerr = LogManager.GetCurrentClassLogger();
loggerr.Info("Check the AWS Console CloudWatch Logs console in us-east-1");
loggerr.Info("to see messages in the log streams for the");
loggerr.Info("log group NLog.ConfigExample");
}
static void ConfigureNLog()
{
var config = new LoggingConfiguration();
var consoleTarget = new ColoredConsoleTarget();
config.AddTarget("console", consoleTarget);
var awsTarget = new AWSTarget()
{
LogGroup = "NLog.LogPlataforma",
Region = "us-east-1"
};
config.AddTarget("aws", awsTarget);
config.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Debug, consoleTarget));
config.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Debug, awsTarget));
LogManager.Configuration = config;
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.AddDebug();
logging.AddEventSourceLogger();
})
.UseNLog();
}
}
我做错什么了吗?