首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SmartAssembly自动记录错误并终止应用程序

使用SmartAssembly自动记录错误并终止应用程序
EN

Stack Overflow用户
提问于 2013-10-11 13:56:24
回答 2查看 585关注 0票数 1

我在应用程序中使用SmartAssembly进行通用代码混淆和错误报告。

如果我的应用程序遇到一个未处理的异常,我希望将异常记录下来,然后在没有任何用户交互的情况下终止应用程序。是否有可能创建一个允许这样做的SmartAssembly项目?

我尝试过在SmartAssembly图形用户界面中以及在命令行上设置这个项目,但没有成功。下面是我尝试过的命令和参数,但到目前为止,我还无法确定如何让它终止应用程序,并在没有用户输入的情况下记录错误。

创建SA项目:

代码语言:javascript
复制
"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"

构建项目:

代码语言:javascript
复制
"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com" /build shell.saproj
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-14 16:10:58

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函数如下所示:

代码语言:javascript
复制
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();
    }

这是最终结果的要点,如果你很困惑的话。

使用GUI或通过cmd创建项目文件:

代码语言:javascript
复制
"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构建:

代码语言:javascript
复制
"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com" /build shell.saproj
票数 2
EN

Stack Overflow用户

发布于 2013-10-11 15:00:11

根据UsingTheCommandLine网站上的例子

你应该把“标准”改为“自动”,这应该是在没有出现用户对话框的情况下发送错误报告。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19319997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档