如何在自定义引导程序应用程序中设置或获取所有日志 [英] How to set or get all logs in a custom bootstrapper application

查看:36
本文介绍了如何在自定义引导程序应用程序中设置或获取所有日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的自定义 Burn 托管引导程序应用程序中,我想要一种设置安装程序默认日志目录的方法,以便客户可以轻松找到安装日志.如果这不能做到,我想要一个合适的方式在安装后复制日志文件.

In my custom Burn managed bootstrapper application, I want a way to set the default log directory of the installer so that customers can easily find the installation logs. If this can't be done, I would like a suitable way to copy the log files after installation.

我尝试在我的设置项目(即 Bundle.wxs)和我的托管引导程序应用程序中设置 WixBundleLog 变量失败.此外,我的引导程序应用程序足够通用,因此可以与各种产品/安装包一起使用,因此我需要一个足够灵活的解决方案来设置/获取每个包的安装日志,而无需对包名称进行硬编码在我的引导程序应用程序中.

I tried unsuccessfully at setting the WixBundleLog variable in my setup project (i.e. Bundle.wxs) and in my managed bootstrapper application. Also, my bootstrapper applicaton is generic enough so that it my be used with a variety of products / install packages, so I need a solution that is flexible enough to set / get the installation logs for each package, without hard-coding the package name in my bootstrapper application.

似乎应该有一种方法可以在不强制用户在命令行上使用-l"或-log"的情况下做到这一点.

It seems there should be a way to do this without forcing the user to use "-l" or "-log" on the command line.

推荐答案

WixBundleLog 是指定日志文件的刻录变量.无法在包中覆盖它,因为您无法在包含Wix"前缀的包中设置变量.在引导程序应用程序中覆盖它也不起作用,因为引导程序继续记录到其默认值.

WixBundleLog is the burn variable that specifies the log file. It is not possible to override it in the bundle because you cannot set a variable in a bundle that contains the "Wix" prefix. Overriding it in the bootstrapper application doesn't work either because the bootstrapper continues to log to its default.

刻录引导程序为引导程序日志和安装包日志设置字符串变量.我在列表中跟踪这些变量.所以在我的构造函数中,我有类似的东西:

The burn bootstrapper sets string variables for the bootstrapper log and the installation package logs. I keep track of these variables in a list. So in my constructor I have something like:

this.LogsDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), @"Company_Name\Logs\Installer\", DateTime.Now.ToString("yyyyMMdd_hhmmss"));
_logVariables = new List<string>();
_logVariables.Add("WixBundleLog");

Burn 以 [WixBundleLog]_PackageId 格式为日志文件设置字符串变量.在我的引导程序应用程序中,当 PlanPackageComplete 事件被触发时,我有一个事件处理程序,其中包含以下代码以将变量添加到我的列表中.

Burn sets string variables for the log files in the format [WixBundleLog]_PackageId. In my bootstrapper application when the PlanPackageComplete event is fired, I have an event handler that includes the following code to add the variables to my list.

//set *possible* log variables for a given package
_logVariables.Add("WixBundleLog_" + e.PackageId);
_logVariables.Add("WixBundleRollbackLog_" + e.PackageId);

在安装结束时或者如果我的引导程序遇到错误,我会调用以下方法:

At the end of installation or if my bootstrapper encounters an error, I call the following method:

private void CopyLogs()
{
     if (!Directory.Exists(this.LogsDirectory))
         Directory.CreateDirectory(this.LogsDirectory);

     foreach (string logVariable in _logVariables)
     {
         if (this.Bootstrapper.Engine.StringVariables.Contains(logVariable))
         {
             string file = this.Bootstrapper.Engine.StringVariables[logVariable];
             if (File.Exists(file))
             {
                 FileInfo fileInfo = new FileInfo(file);
                 fileInfo.CopyTo(Path.Combine(this.LogsDirectory, fileInfo.Name), false);
             }
         }
     }
 }

这篇关于如何在自定义引导程序应用程序中设置或获取所有日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆