How To: Obtain Method Name Programmatically For Tracing – Michael Palermo
How To: Obtain Method Name Programmatically For Tracing – Michael Palermo
I am not a fan of hard-coding method names in exception or trace messages. Here is a utility method to allow access to method name at runtime:
1 2 3 4 5 | <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> TraceContext(<span style="color: #0000ff;">string</span> messageFormat) { <span style="color: #2b91af;">Trace</span>.WriteLine(<span style="color: #0000ff;">string</span>.Format(messageFormat, <span style="color: #0000ff;">new</span> System.Diagnostics.<span style="color: #2b91af;">StackFrame</span>(1).GetMethod().Name)); } |
If I call the method above from inside another method:
1 2 3 4 | <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">void</span> Application_AuthorizeRequest(<span style="color: #0000ff;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e) { <span style="color: #2b91af;">Tools</span>.TraceContext(<span style="color: #a31515;">"Inside of {0} event handler"</span>); } |
The resulting output is:
"Inside of Application_AuthorizeRequest event handler"
You May Also Like
A Simple Introduction to Cisco CML2
0 3859 0Mark Jacob, Cisco Instructor, presents an introduction to Cisco Modeling Labs 2.0 or CML2.0, an upgrade to Cisco’s VIRL Personal Edition. Mark demonstrates Terminal Emulator access to console, as well as console access from within the CML2.0 product. Hello, I’m Mark Jacob, a Cisco Instructor and Network Instructor at Interface Technical Training. I’ve been using … Continue reading A Simple Introduction to Cisco CML2
Creating Dynamic DNS in Network Environments
0 629 1This content is from our CompTIA Network + Video Certification Training Course. Start training today! In this video, CompTIA Network + instructor Rick Trader teaches how to create Dynamic DNS zones in Network Environments. Video Transcription: Now that we’ve installed DNS, we’ve created our DNS zones, the next step is now, how do we produce those … Continue reading Creating Dynamic DNS in Network Environments
Government Edition – Encrypting a USB Flash Drive in Windows 10
0 272 2In this video, Security Instructor Mike Danseglio demonstrates how to use BitLocker in Window 10 to secure files on a USB Flash drive that adhere to stricter data protection requirements as found inside Government entities. BitLocker 2-day instructor-led training is now available at Interface: BITLOCK: Planning and Deploying BitLocker Drive Encryption Training Video Transcription: Hi. … Continue reading Government Edition – Encrypting a USB Flash Drive in Windows 10