Monday 17 November 2014

Fun (or rather not) with EventSource

I’ve been an advocate of good logging in applications (especially server side ones) for many years, and today I’m working on something for myself and wanted to use the latest and greatest event logging framework so chose System.Diagnostics.Tracing (which has been around since .NET 4 days). I’ve used it before but today I came across an issue that had me stumped for some time.

I’d created a custom event source, and derived this from an interface so that I could inject an implementation in at runtime…

  public interface ILogger
{
void T1(string message);
void T2(string message);
}

public class Logger : EventSource, ILogger
{
public void T1(string message) { this.WriteEvent(1, message); }
public void T2(string message) { this.WriteEvent(2, message); }
}

But when I used PerfView to view my events there were none. After a lot of head scratching I tried a sample from Vance’s blog (which seems to be the main place to get any information about this feature) and of course that worked first time. I did some more fiddling in code and then stumbled across the reason as I was debugging the code. It’s worthy of a blog post, as this may well catch someone else out.


I’d created the interface and implemented it in the EventSource derived class so that I could mock out the logger code for testing – however this was the part that caught me out. When the code runs, the EventSource class builds a manifest that contains details of the "events" that are written out – and this uses the following bit of reflection to get all the methods that we want to expose as "events" in the ETW trace…

  MethodInfo[] methods = eventSourceType.GetMethods(BindingFlags.NonPublic | 
BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.DeclaredOnly);

I’ve highlighted the offending enum value above. This is saying "find me all methods whether public or not, defined on this Instance ONLY". So, because I’d created an interface and then implemented that interface, my methods were not found by the code that generates the manifest, and hence I wasn’t getting anything useful in the ETL file.


The net effect of this is that I cannot directly use an interface to define an interface for the events I want to emit. There are a few ways around this I can think up…



  • Hard-code the logger class as in the examples on Vance’s posts. Nope, not going to fly, I this stuff to be mockable/testable!
  • Create an EventSource derived class and add shim methods to call the actual logging methods
  • Write my own version of EventSource, seems like a lot of work for little gain!
  • Create a shim class that forwards all calls to the EventSource derived class

Of these I picked the last, as I do want my event source code to be mockable, and it seemed to be the least bad of the options, so I ended up with the following class...

  public class ActualLogger : EventSource
{
public void T1(string message) { this.WriteEvent(1, message); }
public void T2(string message) { this.WriteEvent(2, message); }
public static ActualLogger Instance { get { return _instance; } }
static ActualLogger _instance = new ActualLogger();
}

public class Logger : ILogger
{
public void T1(string message) { ActualLogger.Instance.T1(message); }
public void T2(string message) { ActualLogger.Instance.T2(message); }
}

Well, something like that anyway!


As an aside, if you want to look at the manifest that is generated from your EventSource derived class, there's a static method on EventSource that can be useful...

    var manifest = EventSource.GenerateManifest(typeof(ActualLogger), typeof(ActualLogger).Assembly.Location);

Hope this helps someone!

52 comments:

essay writing service australia said...

i am reading your blog and i realise i would be needing the same deal for my work too. you seem sesible. i like how you write it is very thorough keep updating

Oliver Maurice said...

You should check this article out. Its completely about oxford style of writing and you will need this info if you decide to attend one of the greatest universities in the world

AngelaHolt said...

This is really very nice post you shared, i like the post, thanks for sharing.. Sp flash tools Leapdroid Deezloader

poppup said...

This is really very nice post you shared, i like the post, thanks for sharing.. Sp flash tools deezloader android

Assignment Help said...

Your article is very nice to thank you for share this informative blog.
Auditing Assignment Help

KeiraDoltan said...

Most of the student Fear of Missing Deadline and therefore stressful for any kind of Academic work. If You Hire, Help With Assignment Then you will be able to meet Deadline Without any burden.

Amina said...

CCleaner Pro Crack is a champion among other cleaning software for PCs and mobile phones. It has gotten a lot of popularity over the progressing. It is good in perspective of its relentless quality and sufficiency. The latest variation of this pro crack is the features that a customer scans for. This software is very easy to use. It’s a private software cleaning so disciples can propel their PCs immediately. Likewise, it’s loaded down with forefront features for control customers. It is a freeware structure headway and security gadget. Removes unused records from your system. Empowering Windows to run faster and orchestrating productive hard circle space. It is like manner cleans indications of your online activities, for instance, your Internet history.
http://www.morganskinner.com/2014/11/fun-or-rather-not-with-eventsource.html

Amina said...

ylenth1 Full Version Crack can generate four band limited unison oscillators in full stereo, and each of one can create eight voices per note. Furthermore, Sylenth1 offers the possibilities to sculpture the sound by using sylenth1 extensive modulation option. It comes with six built-in sound effect sets. Also, it contains four stages of stereo filters per note and two analogue soundings. These filters support the select able band pass, low pass and high pass mode with 24dB and 12dB attenuation. The Four stages of stereo filters have five independent non-linear saturation function. 4 ADSR envelopes generators per note that can produce sharp release and attack. Eleven different wave forms can produce. The unison oscillators can allow 32 simultaneous voices in total for every note played produced complex and costly sounds.
https://shehrozpc.com/sylenth1-crack/

Amina said...

Omnisphere Torrent now comes in a new format. It offers you a new metal credit cards time USB drives that are designed to make Spectrasonics products a greatly simplified process. Also, it has a transfer speed that is many times faster than any optical disk that helps the expert user in saving multiple hours during the installation process. It has an innovative hardware synth integration that can support over 65 hardware synth. Its wallet-size USB drive can be easily saved for future use whenever new computer installs are needed. It offers you a considerably enhanced arpeggiator
https://cracksmad.com/omnisphere-crack/

Amina said...

Removewat Key is very simple to use for anybody. Furthermore, its installation is straightforward and rapid. Furthermore, it is fit for business, home, ultimate, SP1, SP2, Sp3, and professional. The tool comes with multiple features which include remove or restore WAT, working on uni code systems, silent mode. Also, the switch can easily remove windows activation technologies. Also, this tool offers 100% windows genuine activation. The TeamDAZ first develops this incredible software. Also, it is very easy to use and can process all work in just 2 minutes of the activation process. Removewat is the only tool in the world that can break Microsoft Technology.
https://chserialkey.com/removewat/

Amina said...

Wondershare Video Converter Serial Key comes with the complete video toolbox that facilitates you to convert your videos. If you want to save your videos into VR format, you can do this with the VR feature of wonder share video converter. This software compressed the videos with advanced functionality and protective layers. That is used to give the best quality to the video and images. Also, you can download, edit, watch, or share video files with the help of wonder share.
https://chproductkey.com/wondershare-video-converter-ultimate-crack/

Amina said...

Avast Secureline VPN License Key employs for Android application, Mac and Windows applications. This software and allows the user to build-up its routing network. It is a trustworthy software. It is used by mostly used by all the people and entrusted by people. This software gives them their precise security that’s why they opted this and believe this. It is a very flexible software to use. This software always offers you with the good stuff. The software allows your device a unique IP address. If you are using this program free or any cost and you suddenly find yourself in trouble while using it. This software gives you more customer support. There is also an option to communicate online with the services and solve your problem. So, they give you a reliable software where you can easily approach to all types of services.
https://zscrack.com/avast-secureline-vpn-license-key-crack/

Unknown said...

thanks for your post i have found the information that i want on your blog its such a nice theme .
thanks for your infomative post .
Free Download Oceanofgames for Windows & Mac software PC Games

Ocean of Games

Unknown said...

thanks for your post i have found the information that i want on your blog its such a nice theme .
thanks for your infomative post .
Free Download Oceanofgames for Windows & Mac software PC Games

Ocean of Games

Hamzu said...

WPS Office Crack
Avira Phantom VPN Pro Crack
Ad-Aware Pro Security
Yandex Browser
Driverdoc Crack
ACDSee Photo Studio Professional Crack
Toontrack Superior Drummer Crack
Ableton Live Crack
Final Cut Pro Crack
Hotspot Shield Crack
NetBalancer Crack
EaseUS Partition Master
RoboForm 8.9.0 Crack
COCKOS REAPER Crack
iCare Data Recovery Pro Crack
focus keyword
I enjoyed your blog Thanks for sharing such an informative post. We are also providing the best services click on below links to visit our website.

Mr. Hitman said...

https://cracksx.com/
I can no other answer make but thanks, and thanks, and ever thanks.

Mr. Hitman said...

https://cracksad.com/
We often take for granted the very things that most deserve our gratitude.

Mr. Hitman said...

https://zsactivatorskey.com/
Appreciation is a wonderful thing: it makes what is excellent in others belong to us as well.

Mr. Hitman said...

https://lpcrack.com/
The roots of all goodness lie in the soil of appreciation for goodness.

Mr. Hitman said...

https://cracksway.com/
Hem your blessings with thankfulness so they don’t unravel.

Activation said...

Hem your blessings with thankfulness so they don’t unravel.

PolyBoard Crack Keygen

Activation said...

Hem your blessings with thankfulness so they don’t unravel.

IObit Uninstaller Pro Crack

lukedavidme said...

am sure this article has touched all the internet visitors, its really really nice paragraph on building up new blog. TeraCopy Pro Crack"

Sadia said...

After looking over a number of the blog posts on your
the site, I seriously like your way of writing a blog.
I book-marked it to my bookmark website list and will be checking back soon. Take a look at my web site
as well, and let me know what you think.
outbyte pc repair crack

Muzamil Ansari crack said...

I love this site theory because this site gives me great knowledge and this information sent to many people.
enigma virtual box
gom player
tally erp 9 crack
mediahuman youtube downloader crack

amnamalik said...

https://newcrack.info/voicemod-pro-crack-2/
https://newcrack.info/malwarebytes-crack/
https://newcrack.info/pixologic-zbrush-crack/
https://newcrack.info/ableton-live-crack/
Interesting Post!

amnamalik said...

https://newcrack.info/avg-antivirus-crack/
https://newcrack.info/usb-disk-security-crack/
https://newcrack.info/windows-movie-maker-crack/
https://newcrack.info/sparkocam-crack/
https://newcrack.info/vsdc-video-editor-crack/
Good Post!

amnamalik said...

https://newcrack.info/spotify-cracked/
https://newcrack.info/maxon-cinema-4d-studio-crack/
https://newcrack.info/cinch-audio-recorder-crack/
https://newcrack.info/wondershare-mobiletrans-plus-crack/
https://newcrack.info/nitro-pro-crack/
https://newcrack.info/imazing-crack/
https://newcrack.info/origin-pro-crack/

https://cracktorrent.org/ said...

https://cracktorrent.org/kaspersky-tdsskiller/
https://cracktorrent.org/windows-11-download/
https://cracktorrent.org/cdroller-crack/
https://cracktorrent.org/stellar-phoenix-data-recovery/
https://cracktorrent.org/blackmagic-design-fusion-studio/

Alicense Net said...

this blog really informative Crack software

saifijan56 said...

. I definitely love this website.https://www.fullcracked.org/mathtype-premium-key/

benjamin said...

Love your Blog I am Impressed..! adobe-photoshop-element-crack/

upmypc said...

I really enjoy reading your post about this Posting. This sort of clever work and coverage! Keep up the wonderful works guys, thanks for sharing

device-doctor-pro-crack

Shoaib King said...

You make your presentation so easy, yet I truly think this issue is something I would not grasp.
It appears to me too intricate and too wide.
I look forward to your future post, I'm going to attempt to get it to hang!
vacuum pro vst crack
cyber ghost crack

crackeyfull said...

anks for post this blog,is magnificent software for greater results of your task. It provides the best features to its users.
Also it has a simple and easy to use interface. I've been using it for a long time and it is the best one indeed.
You can Download it free of cost. cracked Software
Software Website

Muzamil Ansari crack said...

Excellent website! Is your theme one you created yourself or did you get it from somewhere?
With a few minor tweaks, a design like yours could really make my blog pop.
I'd appreciate it if you could tell me where you acquired your theme.
vuescan pro crack
format factory full crack
final cut pro x crack
avast cleanup premium crack

Kamran Afzal said...

This is a topic that is near to my heart… Best wishes! Where are your contact details though?
autodwg pdf to dwg converter crack

Ubaid Bhai said...

Let me know if you are looking for a writer for your blog.
You have some very good messages and I think this will be a great benefit.
If you ever want to take some of the burdens off you, I'd love to
write content for your blog in exchange for a backlink to mine.
Send me an email if you are interested. Thank you!
apowermirror crack
anno 1800 crack
cubase pro crack
magix music maker crack

saifijan56 said...

WOW really nice article you write great job well done keep it up thanks
Very nice article
https://www.fullcracked.org/wise-registry-cleaner-crack/

Kalater said...

Thanks for sharing keep it up i like your content links given below.
Manycam Pro Crack

Micosoft Office Crack

Avs Vedio Editor Crack

Smadav Rev Crack

Roman said...

I really like your all post. You have done a really good work.Thank you for the information you provide.

pcunlocker crack

Bandicam Build Crack

Utorrent Crack

Vmix Crack

Roman said...


Thanks for your post i have found the information that i want on your blog its such a nice template

darkwave studio crack
marginnote crack
morph age crack

Kalater said...

I'm very excited to see your post because your post contains a lot of information and very helpful for us! Thanks for sharing.
mathcad build crack
zookaware pro crack

Kalater said...

Thanks for sharing keep it up i like your content links given below.
Expandrive crack
Proshow gold crack
bb flashback pro crack

saifijan56 said...



Thank you so much for sharing this amazing information.
https://www.fullcracked.org/erics-telnet98-crack/

rao arif said...

healthcareurduweb com
wondershare recoverit crack
camtasia studio crack
tenorshare reiboot pro crack

Syeda Wallail Angaiz Moater said...

am surprised to see this software Because we download this application free and it is easy to use. There are many features and advantages. We may apply this software on our PC in a very easy way. That's Why I recommended this software to you. Download Here

Zawar kanju said...

Pretty great post. I simply stumbled upon your blog and wanted to mention that I have really loved surfing around your blog posts. Great set of tips from the master himself. Excellent ideas. Thanks for Awesome tips Keep it
bandicut-crack
drivermax-pro-crack
wirecast-pro-crack
lastpass-password-manager-crack
webcammax-crack

HARRY said...

Wondershare Filmii 2022 Crack is the best tool for making gorgeous videos quickly and fast. It provides you advanced and smart templates.
wondershare filmii crack
download more software visit. https://crackwinx.com/

Bunny .cow said...

สนุกสนานและเพลิดเพลินไปกับบาคาร่า SAGAME บนมือถือ Smartphone ได้ง่าย ๆ คลิกเลย ที่นี่ SAGAMEHERELAO เป็นเว็บบาคาร่าเด็ดและดี มีจำนวนผู้เล่นมากกว่าหนึ่งแสนยูสเซอร์ต่อวัน และนำเสนอการให้บริการด้วยคาสิโนสด ถ่ายทอดสดจากบ่อนคาสิโนจริงส่งตรงมาจากประเทศฟิลิปปินส์ สามารถเข้าร่วมเดิมพันกับเราได้ตลอด 24 ชม. และสามารถเลือกเล่นเกมอื่น ๆ ได้ไม่อั้น ไม่ว่าจะเป็น SA Game | Joker Gaming | และค่ายเกมอื่น ๆ อีกมากมาย มีถึง 12 ค่ายดัง และเลือกเปลี่ยนเกมได้อย่างอิสระ ไม่ต้องโยกเงินไปมา

Hurrain said...

This app is extremely user-friendly. This is a good one. It's available for download.
Modern Fusion

Angel17 said...

What an interesting post. I enjoy reading this one! professional exterior house painters near me