我正在尝试跟踪/记录有关我正在处理的消息调度过程的一些信息。
当您尝试多次使用参数数组中某个具体位置的对象时,会引发异常。
private void LogRandomInfo(ILogger Log, string processName, string messageType)
{
try
{
Log.LogInformation("{0} : The event {0} has received the info {1}", processName, messageType);
}
catch (Exception ex)
{
throw ex;
}
}
Run Code Online (Sandbox Code Playgroud)
我期待与我们使用string.Format. 在 中string.Format,您可以打印所请求值的任意次数。
因此string.Format("{0} {0} {0}", 1);将打印1 1 1,但
Log.LogInformation("{0} {0} {0}", 1);会抛出 Index 超出数组范围的异常。
有没有简单的解释为什么会发生这种情况?
使用的日志库是Microsoft.Extensions.Logging