Using WiX to create an event source during install of a .NET framework project

Edit: so I guess I wasn’t the only one confused with this stuff, as it’s been my most popular post by far!  If I’ve helped you out or saved you some time, please let me know in the comments :)

In order for this to work, you have to add references to WixUtilExtension and WixNetFxExtension to your WiX project.  Once that’s done, add this inside a <Component> element:

<Util:EventSource xmlns:Util="http://schemas.microsoft.com/wix/UtilExtension" Name="EVENTSOURCEGOESHERE" Log="Application" EventMessageFile="[NETFRAMEWORK40FULLINSTALLROOTDIR]EventLogMessages.dll" />

Obviously replace EVENTSOURCEGOESHERE with your event source name.  NETFRAMEWORK40FULLINSTALLROOTDIR is a property set by the WixNetFxExtension which stores the path to the .NET framework v4 directory, but you can replace this with the corresponding property for the directory containing the relevant EventLogMessages.dll file.  So if you’re using the .NET framework as I was in this example, you’ll also need to add a property for it inside the <Product> element:

<PropertyRef Id="NETFRAMEWORK40FULLINSTALLROOTDIR" />
A complete list of available properties in the WixNetFxExtension is available at  http://wixtoolset.org/documentation/manual/v3/customactions/wixnetfxextension.html