2

I'd like to ask a very specific question about writing to the event viewer using the System.Diagnostics.Tracing.EventSource and .NET 4.6 class.

In the past, if you wanted to use the event viewer channels you needed to write/generate an XML manifest and register it with the operating system. Is this still the case?

If so I'm struggling to find out how to get the build to generate the manifest, I belive this is possible with the EventSource nuget package, but I'd like to use the in built class under the System.Diagnostics.Tracing namespace if possible.

Thanks in advance.

magicandre1981
  • 27,895
  • 5
  • 86
  • 127
PhilH
  • 60
  • 2
  • 7

1 Answers1

5

Take a look at the Microsoft EventRegister Tool package on NuGet:

This package includes eventRegister.exe, which enables validation and registration of user defined EventSource classes. It supports both BCL event sources (classes derived from System.Diagnostics.Tracing.EventSource) and NuGet event sources (classes derived from Microsoft.Diagnostics.Tracing.EventSource).

Install it via Package Management console in VS:

Install-Package Microsoft.Diagnostics.Tracing.EventRegister

This registers your Eventsource classes, so that you can write to Eventlog:

[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);
    }
}

enter image description here

magicandre1981
  • 27,895
  • 5
  • 86
  • 127
  • Thanks for the prompt response, just having a few issues getting that package in through our firewall, but I'll try work around that and let you know how I get on. – PhilH Jun 27 '16 at 15:00
  • get the package with this link: https://www.nuget.org/api/v2/package/Microsoft.Diagnostics.Tracing.EventRegister/1.1.28 (on your smartphone and use it in a local nuget path: http://www.hanselman.com/blog/HowToAccessNuGetWhenNuGetorgIsDownOrYoureOnAPlane.aspx) – magicandre1981 Jun 27 '16 at 15:40
  • were you able to use the Nuget package? – magicandre1981 Jun 29 '16 at 03:46
  • Hello, yes I've been able to generate the resource manifest and dll with the nuget package. I've used wevtutil to register the DLL with the operating system. The channels are appearing in the event viewer, but I'm currently having trouble getting anything to appear in the logs. I've registered the manifest/dll from the bin directory of the project. The event source classes are inside an WCF service. – PhilH Jun 29 '16 at 09:48
  • Strangely enough when I enable the debug channel, I start getting entries in there. – PhilH Jun 29 '16 at 10:55
  • This is working now, I had created a .cmd file to run in a post build event, the cmd file was running the wevtutil.exe command but was building the full path to the man/dll files incorrectly. Thank you! – PhilH Jun 29 '16 at 13:11