如何在自定义引导程序应用程序中设置或获取所有日志

时间:2012-05-24 16:02:10

标签: wix wix3.6

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

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

似乎应该有一种方法可以在不强制用户在命令行中使用“-l”或“-log”的情况下执行此操作。

1 个答案:

答案 0 :(得分:11)

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

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

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 事件时,我有一个事件处理程序,其中包含以下代码以将变量添加到我的列表中。

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

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

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);
             }
         }
     }
 }
相关问题