首页 > 解决方案 > 如何为清单 ETW 创建 dll 程序集

问题描述

我正在使用 ETW。我想使用 wevtutil 注册我的事件源。我使用 EventSource 类创建了清单:

string manifestFile = "manifest.xml";
public Registrer()
{
    var assemblyFile = ""; //How to create assembly file???
    var manifestText = EventSource.GenerateManifest(typeof(ExceptionHundler), assemblyFile);

    using (var wr = new StreamWriter(manifestFile))
    {
        wr.Write(manifestText);
    }
    RegistrEventSource();
}
private void RegistrEventSource()
{
    var cmdCommandForCreatingEventSource = $@"wevtutil.exe im ""{manifestFile}""";
    Console.WriteLine(ExecuteCmdCommand(cmdCommandForCreatingEventSource));
}
private string ExecuteCmdCommand(string strCommand, bool runAsAdmin = true)
{
    Process cmd = new Process();
    cmd.StartInfo.FileName = "cmd.exe";
    if (runAsAdmin)
        cmd.StartInfo.Verb = "runus";
    cmd.StartInfo.RedirectStandardInput = true;
    cmd.StartInfo.RedirectStandardOutput = true;
    cmd.StartInfo.CreateNoWindow = true;
    cmd.StartInfo.UseShellExecute = false;
    cmd.Start();
    cmd.StandardInput.WriteLine(strCommand);
    cmd.StandardInput.Flush();
    cmd.StandardInput.Close();
    cmd.WaitForExit();
    return cmd.StandardOutput.ReadToEnd();
}

我的问题是如何为 EventSource 创建程序集文件?(不使用来自 nuget 的包)。我找到了这个https://docs.microsoft.com/en-us/windows/desktop/WES/message-compiler--mc-exe-,但有些计算机没有 mc.exe。在我正在使用我的项目的每台计算机中,我需要修复 mc.exe (通过安装 SDK )。什么包含程序集文件,有什么方法可以创建它?

标签: c#loggingetw

解决方案


推荐阅读