Search code examples
c#special-charactersnlogargumentexception

While logging weird string using NLog: ArgumentException: 'illegal characters in path.'


I'm trying to log the following string in a logfile:

$"{(char)0}{(char)1}{(char)3}{(char)0}{(char)3}{(char)0}{(char)0}{(char)0}{Line}{(char)0}{(char)7}{(char)232}{(char)3}{(char)0}{(char)9}{(char)31}"

Where Line equals " 59 ". (the integer value can change but not the length (10))

When looking at that string in the watch-window, this is what I see:

enter image description here

Some information about my NLog configuration (according to the watch-window):

((System.RuntimeType)_log._loggerType).AssemblyQualifiedName : 
"NLog.Logger, NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=..."   

_log._loggerType.IsUnicodeClass : false
...

What can I do in order to avoid the mentioned Exception when launching Log.Debug($"Commands=[{Commands}]")?


Solution

  • The problem was caused by a stupid mistake: at the beginning of my class, I had the following declaration:

    private static readonly Logger _log = LogManager.GetCurrentClassLogger();
    

    So, instead of doing Log.Debug(), I needed to do _log.Debug().