gpt4 book ai didi

c# - nlog:方法的参数无效

转载 作者:行者123 更新时间:2023-12-04 00:33:44 27 4
gpt4 key购买 nike

我写了下面的代码:

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>

最佳答案

您在格式中忘记了 {0}

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

关于c# - nlog:方法的参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12453247/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com