2

我写了以下代码:

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

1 回答 1

6

您忘记了格式中的 {0}

public void StartTask()
{
    var i =10;
    Log.Info(" i = {0}", i);
}
于 2012-09-17T04:50:52.080 回答