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!

61 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

Tyson Harold said...

Nice post.

poppup said...

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

meldaresearchusa said...

From our custom affordable term papers, students can hire the best writers and be assured to receive the best custom papers when they search purchase custom research paper written by experts.

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.

meldaresearch said...

Your search for Custom Research Paper Writing Services ends here. Welcome to the home of best essay writers who are qualified in diverse fields. Our
Research Paper Writing Service
is proof that we are right near you. It is easy, place your order and get original plagiarism free assignments. What’s more, we keep everything confidential.

sitampan said...

Gunakan kesempatan emas bermain di wedeqq dan juga fifaqq. Jangan lupa untuk bergabung juga di taipanqq beserta kebanggan situs lipoqq yang dapat memberikan kemenangan yang mutlak.

Lihat juga halaman terkait lainnya dibawah ini :
jurusqq
priaqq
hokiqq
dewaqq

norhan said...


الرائد افضل شركات تنظيف خزانات المياه يسعدنا ان نقدم لكم افضل خدمات
شركة غسيل خزانات بالمدينة المنورة تنظيف خزانات بالمدينة المنورة
افضل شركة تنظيف منازل بالمدينة المنورة شركة تنظيف بيوت بالمدينة المنورة

Florahmelda said...

Students seek professional Custom Papers Writing assistance from Top Rated Term Papers Writingcompany to accomplish any type of essay assigned to them. When you request for urgent Professional Custom Research Paper, they strive to meet your professors’ requirements.

Sankar said...

I have read your blog its very attractive and impressive. I like it your blog.
Final Year Projects for CSE in Dot Net

.Net Training in Chennai

Final Year Project Centers in Chennai

Dot Net Training in Chennai

Sam said...

Assignment help Australia offers custom and professional assignment writing help to both college and university students who are stuck with their research projects, essays, case studies, business reports and need Urgent Assignment Help.

anonymus said...

Poker online situs terbaik yang kini dapat dimainkan seperti Bandar Poker yang menyediakan beberapa situs lainnya seperti http://62.171.128.49/hondaqq/ , kemudian http://62.171.128.49/gesitqq/, http://62.171.128.49/gelangqq/, dan http://62.171.128.49/seniqq. yang paling akhir yaitu http://62.171.128.49/pokerwalet/. Jangan lupa mendaftar di panenqq

Celine.V said...

peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto

noor said...



ارخص شركة شحن عفش

نقل عفش من جدة الى مكة نقل عفش من جدة الى مكة
شركة نقل عفش من جدة الى الامارات نقل عفش من جدة الى الامارات
افضل شركة نقل عفش من جدة الى الرياض نقل عفش من جدة الى الرياض
شركة نقل عفش من جدة الى الدمام نقل عفش من جدة الى الدمام
شركة نقل عفش من المدينة المنورة الى مكة نقل عفش من المدينة المنورة الى مكة


anonymus said...

shopeetoto
shopeetoto
shopeetoto
shopeetoto
shopeetoto
shopeetoto
shopeetoto
shopeetoto

Sam said...

Our experts have the knowledge, skills, and experience to help college and university students with their research papers, essays, case studies and Thesis projects. Looking for My Assignment Help or need Urgent Assignment Help? then look no further and avail our Assignment help Australia which offers the best assignment writing services in Australia.

Gusion said...

pelangiqq
pelangiqq
pelangiqq
pelangiqq
pelangiqq
pelangiqq
pelangiqq
pelangiqq

Gusion said...

http://62.171.145.61/anugerahtoto/
Togel Online
Poker Online
bandarq
Bandar Kometqq
capsa online
agen online qq
agen poker

Admin said...

Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It ‘s really very nice and Useful post.Thanks

microsoft office Serial key full version free download

Admin said...

Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It ‘s really very nice and Useful post.Thanks

vmware workstation pro crack

anonymus said...

https://togelhoky1.blogspot.com/
https://togelresmi8.blogspot.com/
https://togelsgphk8.blogspot.com/
https://situstogelkita.blogspot.com/
https://togelonlinejudi.blogspot.com/
https://togel2020wap.blogspot.com/

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...

Twixtor Keygen is a highly used graphic plugin due to its extensive features. It can be used for Windows 32-bit and 64-bit platforms. The proficiency of this tool, a free trial, is given for a limited period of time. Moreover, its free version is also available with restricted potential features. Twixtor allows you to enjoy the editing with beautiful features. Also, it is accurate as well as a fantastic tool. It will enable you to retime videos using a single speed setting. You can also control retiring based on frames. It exhibits fewer artifacts in the case of crossing objects. In this way, there is less tearing or stretching of objects, and you can adjust them with ease.
https://letcracks.com/twixtor-pro-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/

Amina said...

IsoBuster Crack buster instantly shows you all the tracks and sessions located on the media or documents, combined with all the file system that are present. Corrupt files or lost files can be found based on scanning for file signatures and orphans system files. On the top of the IsoBuster Pro Crack, the buster can decode a large variety of the files, including disc images audio, video, photos, files, and documents. Iso buster will show you which data have corrupt errors. Use this highly functional software to help recover any data believed to lost forever and ever.
https://zsactivationkey.com/isobuster-pro-crack-keygen/

Amina said...

Smadav Pro Crack 2020 is the best anti-virus program, that delivers you second layer protection to shield your data from virus disease. This software is the best antivirus software that is made possible for all Windows OS. Most antivirus software cannot be installed with other antiviruses. Also, antiviruses especially designed for chief reality in your PC.
https://ziapc.org/smadav-pro-crack/

Teresa Halminton said...

Because I have a Gmail account, so I found www.Gmail.com for troubleshooting every problems. If you cannot find your problems any where, this website will help you.

fullprokey 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 Full Pro Keys for Windows & Mac software Full Pro Keys

Macpcsoft said...

This is a wonderful and informative website. Thanks for sharing.
Melodyne Crack
Cubase Crack
Disk Drill Crack
Movavi Video Editor Crack

fullprokey 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 Full Pro Keys for Windows & Mac software

Full Pro Keys

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

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

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

fullprokey 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 Full Pro Keys for Windows & Mac software

Full Pro Keys

fullprokey 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 Full Pro Keys for Windows & Mac software

Full Pro Keys

fullprokey 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 Full Pro Keys for Windows & Mac software

Full Pro Keys

How4Crack 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 Full Pro Keys for Windows & Mac software

How4Crack


How4Crack 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 Full Pro Keys for Windows & Mac software

How4Crack

Term Paper Writing Services said...

There are many Online Coursework writing services and Help with Coursework Writing services to choose from for those stuck with their psychology coursework writing services and nursing coursework writing help services.

Fl Studio Crack said...

Wow… what a great article on Blog commenting.
I have various concepts to be clear…now fell better after read this article on blog commenting. Superb.
Free FL Studio Crack for Windows & Mac software

FL Studio Crack

Fl Studio Crack said...

Wow… what a great article on Blog commenting.
I have various concepts to be clear…now fell better after read this article on blog commenting. Superb.
Free FL Studio Crack for Windows & Mac software

FL Studio Crack

Fl Studio Crack said...

Wow… what a great article on Blog commenting.
I have various concepts to be clear…now fell better after read this article on blog commenting. Superb.
Free FL Studio Crack for Windows & Mac software

FL Studio Crack

Fl Studio Crack said...

Wow… what a great article on Blog commenting.
I have various concepts to be clear…now fell better after read this article on blog commenting. Superb.
Free FL Studio Crack for Windows & Mac software

FL Studio Crack

Fl Studio Crack said...

Wow… what a great article on Blog commenting.
I have various concepts to be clear…now fell better after read this article on blog commenting. Superb.
Free FL Studio Crack for Windows & Mac software

FL Studio Crack

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.

Activation said...

I like your post. It's informative and helpful for us. please keep it up.
Thanku.
Serial Key Download

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://cskeygen.com/
As we express our gratitude, we must never forget that the highest appreciation is not to utter words, but to live by them.

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.