2013-10-11 34 views
1

我正在使用SmartAssembly來處理通用代碼混淆以及應用程序中的錯誤報告。使用SmartAssembly自動記錄錯誤並終止應用程序

如果我的應用程序遇到未處理的異常,我希望異常被記錄下來,然後在沒有任何用戶交互的情況下終止應用程序。是否有可能創建一個允許這樣做的SmartAssembly項目?

我已經嘗試在SmartAssembly GUI以及the command-line上設置項目,但沒有運氣。下面是我嘗試過的命令和參數,但到目前爲止,我無法確定如何讓它終止應用程序並在沒有用戶輸入的情況下記錄錯誤。

創建SA項目:

"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com" 
/create shell.saproj input=C:\Repositories\MyApp\src\shell.exe 
/output=shell.exe 
/reportappname="MyTestApp" 
/errorreportingtemplate=standard;continueonerror=false,email:"[email protected]" 
/reportprojectname="Shell" 
/reportcompanyname="My Company" 

生成項目:

"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com" /build shell.saproj 

回答

2

SmartAssembly包括定製ErrorReportingTemplates的幾個例子,
位於Red Gate/SmartAssembly 6/SDK/Exception Reporting/

這些例子集中到幾個類別:

Without UI Standard Custom UI Via Email Secured Proxy Silverlight Silverlight Basic

在這些文件夾中的每一個文件夾中都有一個.csproj文件,您可以擴展該文件以獲得所需的結果。 裏面的Without UI文件夾是我們以後是項目,題爲Sample 01 - Without User Interface.csproj

如果你只是一個.dll後使用,不關心一個可重複使用的解決方案,直接編輯這個文件,然後用這個.dll文件(替代方法是創建一個新項目,並將參考文件拉入SmartAssembly.SmartExceptionsCore)。

編輯OnReportException功能如下所示:

protected override void OnReportException(ReportExceptionEventArgs e) 
    { 
     for (int i=0; i<3; i++) 
     { 
      if (e.SendReport()) break; 
     } 
     e.TryToContinue = false; 
     System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess(); 
     proc.Kill(); 
    } 

Here's a Gist of the final result,如果你困惑。

與GUI或通過CMD創建項目文件:

"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com" 
/create shell.saproj input=C:\Repositories\MyApp\src\shell.exe 
/output=shell.exe 
/reportappname="MyTestApp" 
/errorreportingtemplate=MySmartAssemblyLogger.dll;continueonerror=false,email:"[email protected]" 
/reportprojectname="Shell" 
/reportcompanyname="My Company" 

與GUI或通過CMD建設:

"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com" /build shell.saproj