【发布时间】:2016-04-13 02:27:21
【问题描述】:
我在现场见过很少这样的例子,但是所有的例子都有错误,占位符被命名错误或参数和占位符的数量存在差异,我的日志如下所示
Logger.InfoFormat("Successfully connected to outgoing queue for platform {0}. QueueManagerName = {1}, HostName = {2}, ChannelName = {3}, QueueName = {4}", Platform.ID, Platform.MqGatewayParams.QueueManagerName, Platform.MqGatewayParams.HostName, Platform.MqGatewayParams.ChannelName, Platform.MqGatewayParams.OutgoingQueueName);
InfoFormat 方法:
public void InfoFormat(string className, string methodName, string format, object arg0, object arg1, object arg2)
{
_log4NetLogger.InfoFormat(GetMessageString(className, methodName, format), arg0, arg1, arg2);
}
在内部它调用 GeMessageString
private string GetMessageString(string className, string methodName, object message)
{
return string.Format("[{0}::{1}] {2}", className ?? string.Empty, methodName ?? " ", message ?? " ");
}
谁能告诉我我在这里做错了什么?
【问题讨论】:
-
你遇到了什么错误?
-
我给出的主题“StringFormat期间的异常:索引(从零开始)必须大于或等于零且小于参数列表的大小”
-
您确定这是您的
InfoFormat方法的签名吗?因为如果这是真的,你在调用它时完全搞砸了参数。 -
@Ivan Stoev 非常感谢哥们,你的一行让我很开心的问题完全不在意了 :),是的,我只是搞砸了参数
标签: c# string.format