WiX安装EventSource

Ice*_*man 4 c# wix eventlog-source event-log wix3.5

我基于这个例子创建了我的事件源.我的事件源看起来像这样:

[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);
    }
}
Run Code Online (Sandbox Code Playgroud)

该示例使用代码来模拟安装/卸载过程.从其他一些SO问题中,我看到了另一个使用事件消息文件安装事件源的示例.

但它缺少一些很好的例子,说明如何安装/注册由清单定义的EventSource.我正在调查使用CustomAction做类似的事情:

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

但是想知道你有什么建议吗?

Ice*_*man 5

一些搜索后计算出来.在WixUtilExtension中,有内置支持.在引用它并添加命名空间之后,它非常简单.

以下是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>
Run Code Online (Sandbox Code Playgroud)

我必须做的唯一技巧是减少组件ID和文件ID(用于匹配文件名)的长度,以避免以下错误:错误25540.配置XML文件时出现故障.