WiX Wednesday 1.4 Create a Custom Event Log in the Event Viewer

Intro

Oh man, have I been dreading this blog post. I wrote about 3-4 of these Custom Event Log Components last year, and basically I’m having to re-learn it in order to try to describe it, so apologies if the detail is a little light…

Assuming you are using WiX 3.7, you first need to add a reference to WixUtilExtension to your Votive project (the Visual Studio project). First I add a .evtx file so that all the logs are stored here directly so that they are not taking up space in other event logs (if you have particularly verbose logging your sys admins are going to love you for creating your own log file. Be sure to remind them of that…)

This bit goes in the Product.wxs file:

 <DirectoryRef Id="TARGETDIR">
 <Component Id="RegistryEntries" Guid="{6D29EFAC-56EA-4813-98BE-210B2778107F}">
 <RegistryKey
 Root="HKLM"
 Key="SYSTEM\ControlSet001\services\eventlog\SvcHostLogs"
 Action="createAndRemoveOnUninstall">
 <RegistryValue
 Name="SvcHostLogs"
 Value="%SystemRoot%\system32\winevt\Logs\SvcHostLogs.evtx"
 Type="expandable"
 KeyPath="yes" Action="write"/>
 </RegistryKey>
 </Component>
 </DirectoryRef>

You can then add an EventSource element under a component. I have add both registry entries and event logs as Components.


<Feature Id="ProductFeature" Title="ServiceHost" Level="1">
 <ComponentRef Id="RegistryEntries"/>
 <ComponentGroupRef Id="EventLogs"/>
 </Feature>

You may need a reboot of the server once these are installed first time. You definitely need to run the MSI as an admin as we are inserting keys into the Registry. Note that we are removing the registries on an uninstall as leaving them in there creates havoc for when we try to reinstall.

I put this fragment of WiX in it’s own file in the Votive project. It doesn’t make much difference other than making it tidier.


<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
 <Fragment>
 <DirectoryRef Id="INSTALLLOCATION">
 <Component Id="ServiceHost_Event_Log" Guid="{260DFE60-8828-40C2-A124-81D28CD9A6EE}">
 <util:EventSource Log=SvcHostLogs"
 Name="ServiceHost"
 EventMessageFile="C:\Windows\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll" KeyPath="yes"/>

</Component>
 </DirectoryRef>
 <ComponentGroup Id="EventLogs">
 <ComponentRef Id="ServiceHost_Event_Log"/>
 </ComponentGroup>
 </Fragment>
</Wix>

Summary

There are more than one way to do create a Custom Event Log, however this one works for both x64 and x86, as well as for Windows and Web based installers for WiX. I’ve also seen this one copied and pasted by devs for new installers and there have been no complaints. Next week I will be showing you how to set the default size of your custom file.

Sources

  1. Download WiX from CodePlex here.
  2. As I said, I don’t think the manual for WiX is all that great. It feels like it’s been written by an expert in WiX for an expert in WiX. But I guess at least there is a manual.
  3. There’s also a very comprehensive tutorial written about WiX that explains it in far greater detail than I have here. It also provides plenty of examples. Such as in the advanced sections there is a tutorial on creating your own custom UI.
  4. I’ve probably short-changed msiexec. Aside from running msiexec /? in the cmdline, there’s plenty of examples on the TechNet site.
  5. There’s even a book available! I’ve not read it, however the reviews on amazon.com seem positive. For such an esoteric piece of software, and at a reasonable price it’s worth a go? Maybe I’ll buy it and review it at the end of this series….

Author: Richie Lee

Full time computer guy, part time runner. Full time Dad, part time blogger. Knows a thing or two about Pokémon. Knows too much about SQL Agent. Writer of fractured sentences. Maker of the best damn macaroni cheese you've ever tasted.

1 thought on “WiX Wednesday 1.4 Create a Custom Event Log in the Event Viewer”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s