第一件事:
我在版本 2.0.0 中使用带有记录器 NLog 的 Visual Studio 2010。
当我在使用单元测试项目时尝试调试我的一种方法时,会发生一个特定错误:
`Locating source for 'c:\NLogBuild\src\NLog\Logger.cs'. (No checksum.)
The file 'c:\NLogBuild\src\NLog\Logger.cs' does not exist.
Looking in script documents for 'c:\NLogBuild\src\NLog\Logger.cs'...
Looking in the projects for 'c:\NLogBuild\src\NLog\Logger.cs'.
The file was not found in a project.
Looking in directory 'c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\'...
Looking in directory 'c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc\'...
Looking in directory 'c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\atl\'...
Looking in directory 'c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\'...
The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: c:\NLogBuild\src\NLog\Logger.cs.
The debugger could not locate the source file 'c:\NLogBuild\src\NLog\Logger.cs'`
我试图在stackoverflow上找到这个错误,但找到的解决方案并没有解决它。我尝试了几件事:
- 重新安装记录器 NLog
- 更新对 Nlog.dll 和 NLogExtended.dll 的引用
- 排除引用并卸载 nlog 后重新启动我的操作系统
- 从项目中排除文件,再次包括它并重建项目,如这个问题中所说的Stackoverflow 上的链接
该错误并非发生在我的所有方法中。我可以调试某种方法,但如果我尝试使用其他方法,我会收到此错误。
编辑:当我尝试进入该方法Check(outputPath, append)
时,会发生错误。在这种情况下,我必须使用记录器,并且我在其他一些方法中使用记录器,但我没有收到错误。
[TestMethod()]
public void RunMethodCheckTest()
{
string[] cmdArgs = { };
WebserviceReader.RunMethodCheck(cmdArgs);
}
public static void RunMethodCheck(string [] cmdArgs)
{
string xmlPath = null;
string outputPath = null;
bool noRun = false;
bool append = false;
if (cmdArgs != null)
{
for (int i = 0; i < cmdArgs.Length; i++)
{
cmdArgs[i] = cmdArgs[i].ToLowerInvariant();
if (cmdArgs[i].Equals("/?"))
{
ShowHelpText();
return;
}
if (cmdArgs[i].Substring(0, 7).Equals("/output:"))
{
outputPath = cmdArgs[i].Substring(cmdArgs[i].Length - 4).Equals(".xml") ? cmdArgs[i].Substring(8) : cmdArgs[i].Substring(8) + ".xml";
}
else if (cmdArgs[i].Substring(0, 7).Equals("/input:"))
{
outputPath = cmdArgs[i].Substring(cmdArgs[i].Length - 4).Equals(".xml") ? cmdArgs[i].Substring(8) : cmdArgs[i].Substring(8) + ".xml";
}
else if (cmdArgs[i].Substring(0, 10).Equals("/changeout"))
{
Properties.Settings.Default.OutputDefaultFileName = cmdArgs[i].Substring(cmdArgs[i].Length - 4).Equals(".xml") ? cmdArgs[i].Substring(11) : cmdArgs[i].Substring(11) + ".xml";
noRun = true;
}
else if (cmdArgs[i].Substring(0, 9).Equals("/changein"))
{
Properties.Settings.Default.InputDefaultFileName = cmdArgs[i].Substring(cmdArgs[i].Length - 4).Equals(".xml") ? cmdArgs[i].Substring(10) : cmdArgs[i].Substring(10) + ".xml";
noRun = true;
}
else if (cmdArgs[i].Substring(0, 7).Equals("/append")) { append = true; }
}
}
if (noRun) { return; }
if (String.IsNullOrEmpty(xmlPath))
{
xmlPath = MethodCheck.WebserviceReader.GetApplicationFolderName() + "\\" + MethodCheck.Properties.Settings.Default.InputDefaultFileName;
}
if (String.IsNullOrEmpty(outputPath))
{
outputPath = MethodCheck.WebserviceReader.GetApplicationFolderName() + @"\" + MethodCheck.Properties.Settings.Default.OutputDefaultFileName;
}
MethodCheckType methodCheck = new MethodCheckType(xmlPath);
methodCheck.Check(outputPath,append);
}
public void Check(string outputPath, bool append)
{
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
double time;
StringBuilder output = new StringBuilder();
String valueExecute;
String newLine = Environment.NewLine;
for (int i = 0; i < this.WebService.Length; i++)
{
try
{
watch.Reset();
watch.Start();
valueExecute = this.WebService[i].Execute();
watch.Stop();
time = watch.ElapsedMilliseconds;
output.Append("Executed:\n" + this.WebService[i].URL + newLine + "Time: " + time + " Milliseconds");
Console.WriteLine(output.ToString());
output.Append(newLine + "Expected:\t" + this.WebService[i].ReturnValue + newLine + "Got:");
output.Append(newLine + valueExecute + newLine + newLine);
}
catch (Exception ex)
{
output.Append("Failed Webservice:\n" + this.WebService[i].URL + newLine);
Console.WriteLine(output.ToString());
logger.LogException(LogLevel.Error, "Failed Webservice:\t" + this.WebService[i].URL, ex);
continue;
}
}
MethodCheck.WebserviceReader.WriteToFile(output.ToString(),outputPath,append);
}
如果我不在该方法Check(string, bool)
中使用记录器,也会发生错误。