Search code examples
c#influxdbnlog

Using NLog with InfluxDB


I want to configure Nlog.config to log into InfluxDB the same as logging to Seq. I couldn't find any InfluxDB extension for NLog. Do I need just to implement my own NLog.Targets.Targetor there is already something that works with InfluxDB?


Solution

  • Have you tried NLog.Targets.InfluxDB ?

    <nlog>
        <extensions>
            <add assembly="NLog.Targets.InfluxDB"/>
        </extensions>
    
        <targets>
            <target type="InfluxDB"
                    name="influx"
                    Host="https://yourinfluxhost.com"
                    Bucket="MyBucket"
                    Token="inFluXApi=K3y"
                    Org="Organisation">
                <field name="data1" value="${event-properties:data1:format=@}" />
                <tag name="data2" value="${event-properties:data2:format=@}" />
            </target>
        </targets>
    
        <rules>
            <logger name="*" minlevel="Trace" writeTo="influx" />
        </rules>
    </nlog>
    

    Ex.

    log.Info("This field {@data1} and tag {@data2} are sent to InfluxDB", data1, data2);
    

    See also: https://github.com/tomcheney/nlog-influx-target