Shipping logs to Logz.io from NLog gets fail

edx
edx
Member
506 Points
24 Posts

I have .netcore rest api application with NLog logging mechanism. And working fine to file, email.
But now, I'm trying to ship to logz.io as mentioned in: https://docs.logz.io/shipping/log-sources/dotnet.html.

NLog config:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="Warn"
      internalLogFile="temp\internal-nlog.txt">

  <!-- Load the ASP.NET Core plugin -->
  <extensions>
    <add assembly="NLog.Web.AspNetCore"/>
    <add assembly="Logzio.DotNet.NLog"/>
  </extensions>

  <!-- the targets to write to -->
  <targets>
    <!-- write logs to file -->
    <target xsi:type="File" name="allfile"
            archiveEvery="Day"
            archiveNumbering="Rolling"
            maxArchiveFiles="15"
            archiveFileName="${basedir}\temp\Archive\nlog-all-${shortdate}.zip"
            enableArchiveFileCompression="true"
            fileName="${basedir}\temp\nlog-all-dev-${shortdate}.log"
            layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|${message} ${exception}" />


    <target name="logzio" type="Logzio"
            token="shipping-token"
            logzioType="nlog"
            listenerUrl="https://listener.logz.io:8071"
            bufferSize="100"
            bufferTimeout="00:00:05"
            retriesMaxAttempts="3"
            retriesInterval="00:00:02"
            debug="true">
            <contextproperty name="host" layout="${machinename}" />
            <contextproperty name="threadid" layout="${threadid}" />
    </target>
    
  </targets>

  <!-- rules to map from logger name to target -->
  <rules>
    <!--All logs, including from Microsoft-->
    <logger name="*" minlevel="Trace" writeTo="allfile" />

    <logger name="*" minlevel="Info" writeTo="logzio" />
  </rules>
</nlog>

C# controller have this line :

private static Logger logger = LogManager.GetCurrentClassLogger();

and then I try to ship my logs using something like :

logger.Fatal("Something bad happens, ship to logz.io");

Nothing is appearing on Logz.io web portal, no logs are shipped there.

Also, checking internal-nlog.txt no error is logging

Views: 1625
Total Answered: 2
Total Marked As Answer: 1
Posted On: 06-May-2020 00:52

Share:   fb twitter linkedin
Answers
Raj
Raj
Member
496 Points
21 Posts
         

NLog by default eats all exceptions, so problems with logging will not cause the application to break. So, if you want to see exception then you can do following configuration:

  • Add throwConfigExceptions="true", will make NLog complain when something is wrong with the configuration.
  • Set internalLogLevel="Trace"

I.e. make following change in config:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="Trace"
      throwConfigExceptions="true"
      internalLogFile="temp\internal-nlog.txt">

Now, even you can see errors in internal-nlog.txt file too.

Posted On: 06-May-2020 22:28
edx
edx
Member
506 Points
24 Posts
         

Thanks. Now, found the exact error and after fixing it logs are appearing on logz.io

Posted On: 07-May-2020 00:27
 Log In to Chat