1

I am trying to do a little spike and I cannot get log file generated.

This is my NLog configuration:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
  </configSections>

  <startup> 
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>  

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.2.4.0" newVersion="3.2.4.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>


  <nlog throwExceptions="true"
        internalLogLevel="Warning"
        internalLogFile="Rebus.Tests.Output.NLog.Internal.log"
        internalLogToConsole="true"
        xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <targets>
      <target name="normalLogfile" type="File" fileName="${basedir}/Rebus.Tests.Output.log" />
      <target name="normalConsole" type="Console" detectConsoleAvailable="true" />
    </targets>

    <rules>
      <logger name="NormalLog" minlevel="Trace" writeTo="normalLogfile, normalConsole" />
    </rules>

  </nlog>

</configuration>

And here is my static Main in the Console Application:

    var logger = LogManager.GetLogger("NormalLog");

    logger.Error("This is a log error line");

But nothing is logged neither LogFile nor Console.

The application.exe.config is in the bin/Debug runtime folder. And I am looking for the log file with SearchEverything so it will found in any folder where it is.

Adding some information to this question if I put a breakpoint to inspect logger variable I can see no configuration was read:

enter image description here

ferpega
  • 3,182
  • 7
  • 45
  • 65

1 Answers1

2

Try to change

var logger = LogManager.GetLogger("NormalLog");

to

var logger = LogManager.GetLogger("normalLogfile");

because as far as I know you have to get the logger via target-name and not via rule-name.

//edit

Have you tried to remove the nlog attributes in you app.config? Just to be sure none of them is the problem.

Mighty Badaboom
  • 6,067
  • 5
  • 34
  • 51
  • Same behavior: logger is empty. Anyway, I think the `named logger` string in `GetLogger` method is a rule name in config.file. – ferpega Jun 14 '17 at 10:38
  • According to the NLog docu you have to use the Logger's name when using the `GetLogger` method. Have you tried to remoce the nlog attributes in you app.config? Just to be sure none of them is the problem. – Mighty Badaboom Jun 14 '17 at 10:52
  • That was the problem @mightybdaboom The Nlog attributes. Some of them must be not supported and is invalidating all NLog configuration. Please, put that as answer to mark it. Thanks. – ferpega Jun 14 '17 at 11:13
  • Once it was running fine I have tested with rule-name `NormalLog`and all is Ok. I also have tested with target-name and all the configuration is failing with an empty one again. – ferpega Jun 14 '17 at 11:19