user1260827
user1260827

Reputation: 1520

nlog: not working arguments for methods

I wrote the following code:

public class Log
{
    public static  void Info(string message, int arg)
    {
         Logger.Info(message, arg);                
    }
}
public class Task
{
    public void StartTask()
    {
        var i =10;
        Log.Info(" i = ", i);
    }
}

But in the log file contains:

2012-09-17 10:41:00.0789 | Info | i= 

This is config file:

<?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" throwExceptions="true">

  <targets>
    <target name="logfile" xsi:type="File" fileName="C:\KazbiletLog.txt" layout="${longdate} | ${level} | ${message} ${exception:format=ToString,StackTrace}${newline}" />
  </targets>

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

Upvotes: 2

Views: 3159

Answers (1)

Dmitry Khryukin
Dmitry Khryukin

Reputation: 6438

You forgot {0} in your format

public void StartTask()
{
    var i =10;
    Log.Info(" i = {0}", i);
}

Upvotes: 6

Related Questions