我尝试使用NLog来记录我在Docker桌面的一个容器中运行的ElasticSearch。但是我在Kibana中看不到任何日志,并且NLog内部日志显示错误:
Error ElasticSearch: Server error: ServerError: 400Type: illegal_argument_exception Reason: "Action/metadata line [1] contains an unknown parameter [_type]"
下面是我正在使用的Docker合成文件:
version: "3.8"
services:
elasticsearch:
container_name: elastic-search
image: elasticsearch:8.5.1
restart: "no"
environment:
- xpack.security.enabled=false
- discovery.type=single-node
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
cap_add:
- IPC_LOCK
ports:
- "9200:9200"
volumes:
- C:\development\docker-volumes\elasticsearch:/usr/share/elasticsearch/data
kibana:
container_name: kibana
image: kibana:8.4.3
restart: "no"
environment:
SERVER_NAME: kibana
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
ports:
- "5601:5601"
depends_on:
- elasticsearch
我使用的是NLog nuget软件包:
- 非对数5.0.5
- NLog.扩展.托管5.1.0
- NLog.扩展记录5.1.0
- ElasticSearch7.7.0
我的NLog配置文件如下所示:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Debug" internalLogFile="C:/development/logs/nlog-internal.log">
<extensions>
<add assembly="NLog.Targets.ElasticSearch"/>
</extensions>
<variable name="microservice" value="MyMicroervice"/>
<variable name="component" value="IntegrationTests"/>
<targets async="true">
<target xsi:type="File" name="file"
fileName="C:/development/logs/${microservice}/${shortdate}.log"
layout="${longdate} ${component} ${uppercase:${level}} ${message}" />
<target name="elastic" xsi:type="BufferingWrapper" flushTimeout="5000">
<target xsi:type="ElasticSearch" index="microservice-logs"
uri="http://localhost:9200"
includeAllProperties ="true" >
<field name="Component" layout="${component}" />
<field name="TimeStamp" layout="${longdate}" />
<field name="Level" layout="${uppercase:${level}}" />
<field name="LoggerName" layout="${logger}" />
<field name="Message" layout="${message}" />
<field name="error" layout="${exception:format=tostring}" />
</target>
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
<logger name="*" minlevel="Debug" writeTo="elastic" />
</rules>
</nlog>
这是一个使用xUnit和依赖注入的集成测试项目。
public void ConfigureHost(IHostBuilder hostBuilder)
{
var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development";
_configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{environmentName}.json")
.Build();
hostBuilder.ConfigureHostConfiguration(builder => builder.AddConfiguration(_configuration));
hostBuilder.UseNLog();
}
看起来NLog仍然在发布一些Elastic不希望看到的东西(_type),它不喜欢它。但是我找不到解决这个问题的方法?我是否正确理解了这个问题?
我发现类似的问题指向一个叫做fluentd的东西,并建议改变它的配置,但我没有使用fluentd。除非它是NLog.Targets.ElasticSearch包的依赖项?
如何影响NLog发布到Elastic的“操作/元数据”?
1条答案
按热度按时间8yparm6h1#
弹性v6需要DocumentType,弹性v7不支持DocumentType,弹性v8禁止DocumentType。
可以通过显式指定
documentType=""
将NLog ElasticSearch配置为不包括DocumentType:另请参阅:https://github.com/markmcdowell/NLog.Targets.ElasticSearch/wiki