Push Nlog entries to Fluentd

1,356 views
Skip to first unread message

Luis Fernando Alonzo Herrera

unread,
Jul 18, 2014, 2:35:05 PM7/18/14
to flu...@googlegroups.com
Hi, i need to push nlog entries to fluentd using this Nlog target for .NET NLog.Targets.Fluentd , but didn't find in the documentation how to configure the source (in Fluentd) in order to receive the log entries, has anyone tried it or knows which type of source i need to use?

Thanks in advance
-- Luis

Masahiro Nakagawa

unread,
Jul 18, 2014, 2:54:06 PM7/18/14
to flu...@googlegroups.com
I don't use this client but it seems typical Fluentd clinet.

<source>
  type forward
</source>

Above config in fluentd may work.




--
You received this message because you are subscribed to the Google Groups "Fluentd Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fluentd+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luis Fernando Alonzo Herrera

unread,
Jul 18, 2014, 4:42:34 PM7/18/14
to flu...@googlegroups.com
Worked like a charm, thanks!

Regards,
-- Luis

Fei Yao

unread,
Aug 5, 2014, 9:10:26 PM8/5/14
to flu...@googlegroups.com
Luis,
I've configure the fludentd as "type forward", but NLog.Targets.Fluentd still won't work for me. Would you please share the .Net code you have done?

Thanks

Luis Fernando Alonzo Herrera

unread,
Aug 5, 2014, 11:25:38 PM8/5/14
to flu...@googlegroups.com
Hey Fey,

Unfortunately i dont have that code right know (dont have my job's computer at hand), but in the github repo there is a demo program you can use as base, you just have to modify it to set the proper values for the fluentdTarget object, so for example:

If you defined an input source in the fluentd config as follows:

<source>
  type forward
  port 24224
  bind 0.0.0.0
</source>


and a output as follows:

<match hdfs.*.*>
  type webhdfs
  host namenode.your.cluster.local
  port 50070
  path /path/on/hdfs/access.log.%Y%m%d_%H.${hostname}.log
  flush_interval 10s
</match>


Then your .Net app, should be something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;


namespace NlogTest
{
   
class Program
   
{
       
static void Main(string[] args)         {
           
var config = new NLog.Config.LoggingConfiguration();
           
using (var fluentdTarget = new NLog.Targets.Fluentd())
           
{
                fluentdTarget
.Layout = new NLog.Layouts.SimpleLayout("${longdate}|${level}|${callsite}|${logger}|${message}");
                fluentdTarget
.Host = "localhost";
                fluentdTarget
.Port = 24224;
                fluentdTarget
.Tag = "hdfs.nlog.test";
                config
.AddTarget("fluentd", fluentdTarget);
                config
.LoggingRules.Add(new NLog.Config.LoggingRule("demo", LogLevel.Debug, fluentdTarget));
               
var loggerFactory = new LogFactory(config);
               
var logger = loggerFactory.GetLogger("demo");
                logger
.Info("Hello World!");
           
}
       
}
   
}
}

The fluentdTarget.Tag property must match the output plugin Matching expression.

I had trouble installing the NLog.TargetsFluentd package with NuGet, it has some issue with the last version of the NLog package, so i first installed nlog version 2.1.0 and the installed the NLog target:

install-package NLog -version 2.1.0
Install-Package NLog.Targets.Fluentd

Hope it helps.

Regards.

Fei Yao

unread,
Aug 5, 2014, 11:46:20 PM8/5/14
to flu...@googlegroups.com
Thanks Luis,
I get it work now, it appears that the NLog version I got is too low.

Many thanks
Fei

Luis Fernando Alonzo Herrera

unread,
Aug 5, 2014, 11:54:37 PM8/5/14
to flu...@googlegroups.com
I am glad, good to know.

Regards.
Luis.

Apurva Jalit

unread,
Feb 26, 2016, 7:10:04 AM2/26/16
to Fluentd Google Group, wic...@gmail.com
Hello All,
This thread looks a little old but I cam across it while struggling to use nlog with fluentd. I could get my message upto fluentd using the code shared by Luis here. But is there a way can configure fluent as target in nlog.config? How do we specify layout? Also is there a way we can specify different tag names everytime we log something? (like we specify log level as debug,info etc with the log statement).

Jalal Ahmad

unread,
Mar 21, 2016, 4:50:30 PM3/21/16
to Fluentd Google Group, wic...@gmail.com
Here is the config you can use without modifying your regular code:

<?xml version="1.0" encoding="utf-8" ?>
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >

    <extensions>
      <add assembly="NLog.Targets.Fluentd" />
    </extensions>
  <!-- optional, add some variabeles
  -->
  <variable name="myvar" value="myvalue"/>

  <!-- 
  for information on customizing logging rules and outputs.
   -->
  <targets>

    <!-- 
    add your targets here 
    See https://github.com/nlog/NLog/wiki/Targets for possible targets.
    See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
    -->

    <!--
    Writing events to the a file with the date in the filename. 
    target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
            layout="${longdate} ${uppercase:${level}} ${message}" />
    -->
  <target xsi:type="Fluentd" name="fluentdTarget" 
          host="your host" 
          tag="mytag"
          noDelay="true"
          sendBufferSize="8192"
          sendTimeout="2"
          lingerEnabled="false"
          lingerTime="2"
          emitStackTraceWhenAvailable="false"/>
  </targets>
  <rules>
    <!-- add your logging rules here -->

    <!--
    Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace)  to "f"
    <logger name="*" minlevel="Debug" writeTo="f" />
    -->
    <logger name="*" minlevel="Debug" writeTo="fluentdTarget" />
  </rules>
</nlog>
Reply all
Reply to author
Forward
0 new messages