Question

I've been trying to work with ETW in .net 4.0.

I have started using Microsoft EventSource Library 1.0.4-beta (https://www.nuget.org/packages/Microsoft.Diagnostics.Tracing.EventSource)

Here is the code i written for generating events for my application.

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

    public static string GetManifest()
    {
        return GenerateManifest(typeof(EventSourceLogger), null);
    }

    [Event(200, Level = Microsoft.Diagnostics.Tracing.EventLevel.Informational, Task = EventTask.None, Version = 1,
        Opcode = EventOpcode.Info, Keywords = EventKeywords.None, Channel = EventChannel.Admin,
        Message = "Test Message")]
    public void LogEtwInfoEventMessage(string jsonArgs)
    {
        if (!this.IsEnabled()) return;

        this.WriteEvent(200, jsonArgs);
    }

    [Event(400, Level = Microsoft.Diagnostics.Tracing.EventLevel.Error, Task = EventTask.None, Version = 1,
        Opcode = EventOpcode.Info, Keywords = EventKeywords.None, Channel = EventChannel.Admin, Message = "Test Message")]
    public void LogEtwErrorEventMessage(string jsonArgs)
    {
        if (!this.IsEnabled()) return;

        this.WriteEvent(400, jsonArgs);
    }

    [Event(500, Level = Microsoft.Diagnostics.Tracing.EventLevel.Warning, Task = EventTask.None, Version = 1,
       Opcode = EventOpcode.Info, Keywords = EventKeywords.None, Channel = EventChannel.Admin, Message = "Test Message")]
    public void LogEtwWarningEventMessage(string jsonArgs)
    {
        if (!this.IsEnabled()) return;

        this.WriteEvent(500, jsonArgs);
    }
}

I am not able to generate manifest from listener. Code Below

var manifestXml = EventSourceLogger.GetManifest();

When I try to call this I get NullReferenceException, Please suggest I am missing any thing. Is it possible to push EventMessage to EventViewer using this version.

As Part of this NuGet Package, I have eventRegister, Install Bat, Microsoft.Diagnostics.Tracing.EventSource.targets. I am not really sure how these would help in manifest generate.

If any one have any ideas (or) worked on this, Please help.

Thanks in advance.

Was it helpful?

Solution 3

I was able find a solution for this. Now i am able to register and publish the events to the eventviewer.

http://naveensrinivasan.com/2010/03/17/using-clr-4-0-event-tracing-for-windows-etw-along-with-application-etw/

Thanks.

OTHER TIPS

The answer by @magicandre1981 is correct in the sense that it's not necessary to generate manifests with newer versions of .NET and EventSource. (In fact, it's still taking place, but it's just been hidden behind a build event that gets put into your project file when you're installing the EventSource package.)

However, depending on what you're doing, you might still need to generate the manifest manually. Here's one way to do it:

  1. Either install the EventSource package (Install-Package Microsoft.Diagnostics.Tracing.EventSource) into your project or download and unpack it where you need it
  2. Locate the eventRegister.exe. (It will most likely be somewhere under folder similar to packages\Microsoft.Diagnostics.Tracing.EventRegister.1.1.26\build relative to the package installation folder)
  3. Run the following command:

eventRegister.exe {path-to-dll-with-your-eventsource-class} {manifest-output-file-prefix}

After that you'll see two files per each EventSource class that you have in the dll:

  • {prefix}{EventSource Name}.etwManifest.dll
  • {prefix}{EventSource Name}.etwManifest.man

And those are the ones you can then feed to wevtutil:

wevtutil.exe 
   im {EtwManifestManFile} 
   /rf:"{EtwManifestDllFile}" 
   /mf:"{EtwManifestDllFile}"

You don't need to get the Manifest any longer. You can now directly register the EventSource:

Registering your EventSource

When you install the EventSource NuGet package, the build step previously mentioned generates the following files for each EventSource in your application:

AssemblyName.EventSourceTypeName.etwManifest.man

AssemblyName.EventSourceTypeName.etwManifest.dll.

These files need to be registered with the operating system to enable channel support. To do this you run the following command after the files are in their final deployed location:

wevtutil.exe im EtwManifestManFile /rf:"EtwManifestDllFile"c /mf:"EtwManifestDllFile"

Microsoft explained this in this Blog:

Announcing the EventSource NuGet Package – Write to the Windows Event Log

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top