nlog:没有方法的工作参数

时间:2012-09-17 04:45:49

标签: c# nlog

我写了以下代码:

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);
    }
}

但是在日志文件中包含:

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

这是配置文件:

<?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>

1 个答案:

答案 0 :(得分:6)

您忘记格式为<0}

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