Search code examples
c#wixevent-logwix3.5eventlog-source

WiX to install EventSource


I created my event source based on this example. My event source looks like this:

[EventSource(Name = "Samples-EventSourceDemos-EventLog")]
public sealed class MinimalEventSource : EventSource
{
    public static MinimalEventSource Log = new MinimalEventSource();

    [Event(1, Message = "{0} -> {1}", Channel = EventChannel.Admin)]
    public void Load(long baseAddress, string imageName)
    {
        WriteEvent(1, baseAddress, imageName);
    }
}

The example use code to simulate install/uninstall process. From some other SO questions, I saw another example of installing event source using event message file.

But it is missing some good examples how to install/register the EventSource that defined by manifests. I am investigating using CustomAction to do something like:

wevtutil.exe im <EtwManifestManFile> /rf:"EtwManifestDllFile" /mf:"EtwManifestDllFile"

but wondering if you have any suggestions?


Solution

  • Figured out after some search. In the WixUtilExtension, there is build-in support. After referencing it and adding namespace, it is pretty easy.

    Here are the changes in the Product.wxs:

    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
         xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
    ...
          <Component Id="etwManifest.dll">
            <File Id="etwManifest.dll" KeyPath="yes"
                  Source="$(var.SampleClassLibrary.TargetDir)\SampleClassLibrary.Samples-EventSourceDemos-EventLog.etwManifest.dll" />
          </Component>
          <Component Id="etwManifest.man">
            <File Id="etwManifest.man" KeyPath="yes"
                  Source="$(var.SampleClassLibrary.TargetDir)\SampleClassLibrary.Samples-EventSourceDemos-EventLog.etwManifest.man">
              <util:EventManifest  MessageFile="[etwManifest.dll]"  ResourceFile="[etwManifest.dll]"></util:EventManifest>
            </File>
          </Component>
    </Wix>
    

    The only trick I had to do is reduce the length of component Id and File Id (used to match with the file names) to avoid the following error: Error 25540. There was a failure while configuring XML files.