How to set or get all logs in a custom bootstrapper application
Asked Answered
A

1

5

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.

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.

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

Antagonist answered 24/5, 2012 at 16:2 Comment(0)
A
11

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 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);
             }
         }
     }
 }
Antagonist answered 24/5, 2012 at 16:2 Comment(2)
Wouldn't it be easier to get destination log path from WixBundleLog, then get file name without prefix from this path and file directory, later we could just get all files in directory wich start with saved file name and copy them?Tamra
@VladimirArustamian great suggestion, this worked for me.Rexrexana

© 2022 - 2024 — McMap. All rights reserved.