【问题标题】:Automatically log error and terminate application with SmartAssembly使用 SmartAssembly 自动记录错误并终止应用程序
【发布时间】:2025-12-14 06:05:01
【问题描述】:

我将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:"my@email.com"
/reportprojectname="Shell" 
/reportcompanyname="My Company"

构建项目:

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

【问题讨论】:

    标签: obfuscation error-reporting redgate smartassembly


    【解决方案1】:

    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:"my@email.com"
    /reportprojectname="Shell" 
    /reportcompanyname="My Company"
    

    使用 GUI 或通过 cmd 构建:

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

    【讨论】:

      【解决方案2】:

      根据网站上的例子http://www.red-gate.com/supportcenter/Content/SmartAssembly/help/6.7/SA_UsingTheCommandLine

      您应该将“标准”替换为“自动”,这样可以在不出现用户对话框的情况下发送错误报告。

      【讨论】:

      • 使用 auto 自动记录错误,但我找不到正确的设置来在没有用户交互的情况下额外终止应用程序。
      最近更新 更多