2

I'm trying to configure NLog for my C# application. I've got the logging working but it seems to have a mind of it's own in regards to whitespace. Here is my 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"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >

  <variable name="brief" 
            value="${longdate} | ${level} | ${logger} |: ${message}" />
  <variable name="verbose" 
            value="${longdate} | ${machinename} | ${processid} | ${processname} | ${level} | ${logger} |: ${message}" />

  <targets>
    <target name="myLog" xsi:type="File" fileName="myLog.txt" layout="${verbose}" />
    <target name="console" xsi:type="Console" layout="${brief}" />
  </targets>

  <rules>
    <logger name="*" minlevel="Debug" writeTo="myLog" />
    <logger name="*" minlevel="Info" writeTo="console" />
  </rules>
</nlog>

The log's output currently looks like this:

2016-05-19 12:08:00.0302|DEBUG|Namespace.ClassName|:Some log message here...

For some reason, NLog is getting rid of the spaces I defined in the target's layout attribute. What I would like the log entry to look like is:

2016-05-19 12:08:00.0302 | DEBUG | Namespace.ClassName |: Some log message here...

How do I get NLog to preserve the spaces in the layout attribute?

I've also tried to set the level to a fixed length with padding like this: ${padding:padding=5,fixedlength=true:${level:uppercase=true}} as mentioned in this post, but still no luck.

Community
  • 1
  • 1
Lews Therin
  • 3,707
  • 2
  • 27
  • 53
  • Is this happening in both the file and console output? What version of NLog are you using? –  May 19 '16 at 18:26
  • @Amy Yes it is happening in both the file and the console. I'm using the most current version (4.3.4) from the [NuGet package](https://www.nuget.org/packages/NLog/). – Lews Therin May 19 '16 at 18:29
  • Hm, I cannot reproduce using that version and your configuration. If you create a fresh project and use this configuration, does it happen there too? –  May 19 '16 at 18:36
  • @Amy I'll give that a shot and report back. Thanks. – Lews Therin May 19 '16 at 18:39
  • @Amy Well there is something up with my code...not sure what but I was able to get a brand new project to work with NLog without issue...yet the issue persists in my current project. Oh well, guess I just need to keep digging. Thanks for your help. – Lews Therin May 19 '16 at 19:43

1 Answers1

1

I discovered that NLog doesn't play nice when there is a # character in the path for the solution. Renamed the path and it started working again.

Lews Therin
  • 3,707
  • 2
  • 27
  • 53