asp.net - 无法使用 NLog 从托管在 Windows Elastic Beanstalk 机器上的 ASP.Net 应用程序将日志写入 AWS cloudwatch
问题描述
我创建了一个新的 ASP.Net 应用程序并使用其部署工具包部署在 AWS Elastic Beanstalk 机器上。现在我正在尝试向应用程序添加一个日志框架。我正在使用 NLog 并希望将日志写入 AWS CloudWatch 文件夹。
我已经从 NuGet 安装了 AWS.Logger.NLog 包,并使用如下示例 Logger 类将 NLog.config 文件添加到我的应用程序中。
<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" region="us-east-1"/>
<target name="logfile" xsi:type="Console" layout="${callsite} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile,aws" />
</rules>
</nlog>
public class Logger
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static void LogErrorMessage(String message)
{
logger.Error(message);
}
public static void LogInfoMessage(String message)
{
logger.Info(message);
}
}
当我在本地运行我的应用程序时,示例日志文件夹已成功创建,并且消息将记录在 CloudWatch 上。但是在 ElasticBeanstalk 上部署应用程序后,CW 上没有任何记录。甚至文件夹也没有被创建。
有人可以帮我解决我在这里想念的东西。
解决方案
如果包括<extensions>
怎么办?
<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" region="us-east-1"/>
<target name="logfile" xsi:type="Console" layout="${callsite} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile,aws" />
</rules>
</nlog>
推荐阅读
- fortran - 将派生类型作为可选参数传递时出现分段错误
- azure - 如何使用 ARM 模板副本有条件地为存储帐户提供 N 个角色分配?
- c# - 按列名对 DataView 行进行排序
- snowflake-cloud-data-platform - 雪花 - 期待 VARIANT 但使用 MERGE 获得 VARCHAR 列
- docker - docker撰写网络别名不起作用
- python - Python 中缺少 ByteCounts 标记
- node.js - 如何更改媒体字段上传提供者?
- cuda - 有没有办法为 CUDA 设置多个 gpu?
- standards - 是否有一个公认的标准来命名平凡的用户配置文件字段?
- node-redis - Redis HMSET 是否已弃用?