您應該使用一些跟蹤庫,如one,您可以下載here。 現在你可以使用語句類似這樣的裝點您的相關方法:
using ApiChange.Infrastructure;
class MyAddin
{
static TypeHashes myType = new TypeHashes(typeof(MyAddin);
void RelevantMethod()
{
using (Tracer t = new Tracer(myType, "RelevantMethod"))
{
....
if(bLoaded == false)
t.Error("Could not load adding because of {0}", reason);
}
}
}
然後,您可以啓用通過環境變量_TRACE跟蹤
set _Trace=debugoutput
DebugOutput可以使用Sysinternals的工具DbgView被視爲(無附加只需啓動它並觀察痕跡)。 或者你跟蹤到一個文件
set _Trace=file
跟蹤文件所在位置的可執行文件是如Nunit.exe.txt。如果您將_TRACE設置爲某個隨機字符串,它將跟蹤控制檯和OutputDebugString的幫助,爲您提供幫助。
爲什麼這個跟蹤庫?它實際上是唯一一個能夠在你的方法被遺留時追蹤任何異常的人。當方法包含像上面那樣使用語句進行跟蹤時,這會起作用。如果NUnit選擇忽略你的插件實際上是你的錯誤,那麼你現在就可以發現它。 輸出將是這樣的:
* ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception 18:57:46.665 03064/05180 < {{> ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod 18 :57:46.668 03064/05180 < {{> ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod 18:57:46.670 03064/05180 <}} < ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod拋出異常:System.NotImplementedException:喜這是ApiChange的一個錯誤 .IntegrationTests.Diagnostics.TracingTests.FaultyMethod() 在ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod() 在ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod() 在ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception() 18:57:46.670 03064/05180 <}} < ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod時間2ms的 18:57:46.689 03064/05180 <}} < ApiChange.IntegrationTests.Diagnostics.TracingTests。SomeMethod Duration 24ms
這應該很容易找出爲什麼你的Addin沒有被使用。而且你不需要調試器;-)。
你的, 阿洛伊斯·克勞斯
哇,這聽起來非常有幫助。我會試試看... – kelloti 2011-02-06 21:36:07