markmcdowell / NLog.Targets.ElasticSearch

NLog target for Elasticsearch
MIT License
176 stars 89 forks source link

Exception: System.NotImplementedException. The method or operation is not implemented. occurred #49

Closed thomas1983 closed 5 years ago

thomas1983 commented 7 years ago

Hi,

I got following exception when setting configuration:


  at System.IO.FileSystemWatcher..ctor (System.String path) [0x00006] in <6c708cf596db438ebfc6b7e012659eee>:0 
  at (wrapper remoting-invoke-with-check) System.IO.FileSystemWatcher:.ctor (string)
  at Microsoft.Extensions.FileProviders.PhysicalFileProvider.CreateFileWatcher (System.String root) [0x00036] in <adc84446fdf9439dad10eb552dd7a12d>:0 
  at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor (System.String root) [0x00000] in <adc84446fdf9439dad10eb552dd7a12d>:0 
  at Microsoft.Extensions.Configuration.FileConfigurationExtensions.SetBasePath (Microsoft.Extensions.Configuration.IConfigurationBuilder builder, System.String basePath) [0x0001c] in <3eaff4ea723746dc8a22439ca756850a>:0 
  at NLog.Targets.ElasticSearch.StringExtensions.GetConnectionString (System.String name) [0x0001b] in <d7be43874ee545e280666e78ef3f85b2>:0 
  at NLog.Targets.ElasticSearch.ElasticSearchTarget.InitializeTarget () [0x0000c] in <d7be43874ee545e280666e78ef3f85b2>:0 
  at NLog.Targets.Target.Initialize (NLog.Config.LoggingConfiguration configuration) [0x00072] in <61ea888dc95c4a11a0aa573b1e512ef3>:0 
  at NLog.Targets.Target.NLog.Internal.ISupportsInitialize.Initialize (NLog.Config.LoggingConfiguration configuration) [0x00011] in <61ea888dc95c4a11a0aa573b1e512ef3>:0 
  at NLog.Config.LoggingConfiguration.InitializeAll () [0x0003a] in <61ea888dc95c4a11a0aa573b1e512ef3>:0 
  at NLog.LogFactory.set_Configuration (NLog.Config.LoggingConfiguration value) [0x00055] in <61ea888dc95c4a11a0aa573b1e512ef3>:0 
  at NLog.LogManager.set_Configuration (NLog.Config.LoggingConfiguration value) [0x00000] in <61ea888dc95c4a11a0aa573b1e512ef3>:0 

code:

    var config = new LoggingConfiguration();
            LogManager.ThrowConfigExceptions = true;
            LogManager.ThrowExceptions = true;

            var elasticTarget = new ElasticSearchTarget();
            elasticTarget.Uri = "xxx.xxx.xxx.xxx:9200";
            elasticTarget.IncludeAllProperties = true;
            elasticTarget.Fields = new List<Field> {
                new Field{ Name = "key", Layout = "${date:format=ddMMyyyyHHmmss}" },
                new Field{ Name = "caller", Layout = "${logger}" },
                new Field{ Name = "level", Layout = "${level}"},
                new Field{ Name = "message", Layout = "${message}"},
                new Field{ Name = "information", Layout = "${event-properties:data}"},
                new Field{ Name = "date", Layout = @"${date:format=dd-MM-yyyy HH\:mm\:ss}"},
                new Field{ Name = "exception", Layout = @"${exception:format=tostring}"},
                new Field{ Name = "callsite", Layout = "file: ${event-properties:filename} \n method: ${event-properties:caller} \n line: ${event-properties:linenumber}"}

            };     
            elasticTarget.Index = @"log-${date:format=yyyyMMdd}";

            config.AddTarget(elasticTarget);

            var fileRule = new LoggingRule("*", LogLevel.Trace, fileTarget);
            config.LoggingRules.Add(fileRule);
            var databaseRule = new LoggingRule("*", LogLevel.Trace, methodTarget);
            config.LoggingRules.Add(databaseRule);

            var elasticsearchRule = new LoggingRule("*", elasticTarget);
            elasticsearchRule.EnableLoggingForLevel(LogLevel.Trace);
            config.LoggingRules.Add(elasticsearchRule);
            LogManager.Configuration = config;

edit: Nlog.Targets.ElasticSearch: 4.0.0-beta21 Nlog: 5.0.0-beta11

markmcdowell commented 6 years ago

Hey, which platform where you targeting with this?

alaneo commented 6 years ago

Hi. I'm also having exactly the same issue and error. My XML config looks like this... NLog installed on Xamarin and the config file is loaded correctly. code:


<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      throwExceptions="true"
      throwConfigExceptions="true">
  <extensions>
    <add assembly="NLog.Targets.ElasticSearch" />
  </extensions>
  <targets async="true">
    <target name="elastic" xsi:type="BufferingWrapper" flushTimeout="5000">
      <target xsi:type="ElasticSearch"
              layout="${message}"
              index="logstash-${date:format=yyyy.MM.dd}"
              includeAllProperties="true"
              uri="http://xxx.xxx.xxx.xxx:9200"
              ThrowExceptions = "true">
        <field name="time" layout="${longdate}" />
        <field name="application" layout="My.Mobile.App" />
        <field name="hostname" layout="${machinename}" />
        <field name="logger" layout="${logger}" />
        <field name="level" layout="${level:upperCase=true}"/>
        <field name="message" layout="${message}" />
        <field name="exception" layout="${exception:format=ToString,Data}" />
      </target>
    </target>
    <target name="files" xsi:type="File" fileName="${basedir}/logs/${longdate}-${level:upperCase=true}.log">
      <layout xsi:type="JsonLayout" includeAllProperties="true">
        <attribute name="time" layout="${longdate}" />
        <attribute name="application" layout="My.App" />
        <attribute name="hostname" layout="${machinename}" />
        <attribute name="logger" layout="${logger}" />
        <attribute name="level" layout="${level:upperCase=true}"/>
        <attribute name="message" layout="${message}" />
        <attribute name="exception" layout="${exception:format=ToString,Data}" />
      </layout>
    </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="elastic" />
  </rules>
</nlog>```