SlideShare a Scribd company logo
Back-2-Basics: Exception & Event Instrumentation in .NET
2
Check Out Your Local User Groups!San Diego Cloud Computing User Groupwww.azureusergroup.com/group/sandiegoazureusergroupSan Diego .NET Developers Groupwww.sddotnetdg.orgSan Diego .NET User Groupwww.sandiegodotnet.comSan Diego SQL Server User Groupwww.sdsqlug.org
Win Free Software!RulesProvide your business card (or email and name)*Indicate on the back what software you are interested inOtherwise I will pick Winners will be picked next week*Yes, most likely I’m going to send you and email about my user group (sddotnetdg.org) and or web site (dotNetTips.com)PrizesCodeRush and Refactor Pro from DevExpress (4)SecondCopy (automatic backup software) (5) *CodeIt.Right Standard from SubMain (4)*Requires mailing address and phone number
Summary5
Logging Exceptions & Events
Why Do We Need To?Debugging statements only work in debug builds and while in VSNo way to tell what applications are doing during runtimeNeed to log exceptions for evaluation by support & development teamsNeed to log other information during runtimeLog information for reporting7
Logging Methods You Use?Log to Event log?Custom text files?Custom xml files?Database?….
The .NET SolutionTrace Listeners!Easy to use from any .NET application including ASP.NET!!Extremely configurableEasy to write your own listeners
.NET Trace Listeners
OverviewWrite informative messages about the execution of an application at run time.PhasesInstrumentation — you add trace code to your application. Tracing — the tracing code writes information to the specified target. Analysis — you evaluate the tracing information to identify and understand problems in the application.11
OverviewOutput is written to one to many listeners.Part of the Trace.Listeners collectionOutput Methods:Assert - The specified text; or, if none is specified, the Call Stack. Fail - The specified text; or, if none is specified, the Call Stack.WriteWriteIfWriteLineWriteLineIf
Out of the Box ListenersTextWriterTraceListenerWrites to the TextWriter or Steam classEventLogTraceListenerWrites to an event logEvent works with ASP.NET!DefaultTraceListenerWrites Write and WriteLine messages to the OutputDebugString and to the Debugger.Log method (debug window in VS)
Out of the Box ListenersConsoleTraceListenerWrites output to the console windowDelimitedListTraceListener Writes to the text writer in a delimited text formatXmlWriterTraceListenerWrites to xml file.
ConfigurationDone via code or application config fileTurn off/ on listenersSet trace levelsSet filters
Configuration Example<system.diagnostics>  <sources>    <source name="DefaultSource" switchName="DefaultSwitch">  <listeners>  <add name="FileLog"/>      </listeners></source></sources><switches>  <add name="DefaultSwitch" value="Information" /></switches>  <sharedListeners>  <add name="FileLog“ type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL“ initializeData="FileLogWriter"/>  </sharedListeners></system.diagnostics>
Back-2-Basics: Exception & Event Instrumentation in .NET
Add custom functionality & enhance .NET listenersCustom Trace Listeners
OverviewCreate your own listeners or enhance current listenersInherit TraceListenerOverride:Write - writes the specified message to the listener.WriteLine - Writes a message to the listener.TraceEvent - Writes trace information, a message, and event information to the listener specific output.19
OverviewOverride:TraceData - Writes trace information, a data object and event information to the listener specific output.GetSupportedAttributes - Gets the custom attributes supported by the trace listener.Add to config fileIn place or in addition to the .NET listeners.20
Issues with .NET ListenersXmlWriterTraceListenerDoes not write well formed xmlCreates one huge fileWith ASP.NET it says lockedCan not move, delete etc. Can not view latest trace writesDue to flushing issuesMost other file based listeners most likely suffer from the same issues
Taking Exception & Event logging to the extreme!dotNetTips.Utility Listeners
OverviewListeners part of the dotNetTips.UtilityOpen source project available at http://codeplex.com/dotnettipsCurrent version requires .NET 3.5Fixes/ enhances .NET ListenersAdds new ListenersOutputs A LOT more debugging info!Add custom information during runtime!Built-in configuration!23
Advanced Debugging InfoVia the LogEntry classAutomatic when logging Exceptions:Tread/ Process informationDomain nameApplication informationUser informationComputer informationAuto log class and method where Exception happenedMuch more!
More on LogEntryAdd custom information into a collectionAdditional propertiesCategoryId (GUID)UserMachineNameSeveritySourceSourceVersion
Enhanced ListenersEventLogTraceListenersXmlTraceListenersFixes all issues of the .NET implementation!Writes well formed xml!Does not lock file!Creates a new file for each dayAutomatic delete of old files (configurable)
Added ListenersEmailTraceListenerEmail trace events via smtp serverWebServiceTraceListenerSends trace events to a web service methodTCPTraceListener (coming soon)Sends trace events to TCP listenersWatch events in real time!
Writing Exceptions/ EventsUse LogWriterCustom for logging Exceptions, Events and LogEntryLogging Exceptions and Events uses LogEntry under the hoodWrites to the correct log collection based on type of applicationMethodsWriteEntryMessages (events) and LogEntryWriteException
Back-2-Basics: Exception & Event Instrumentation in .NET
Lets Kick It Up A Notch!Centralized Logging System
The ProblemEach client/ server machine logs locallySupport has to logon to each machine to read eventsNot possible sometimes at client locationNo search capabilitiesServerServerServerLogFileLogFileLogFileServerServerServerLogFileLogFileLogFile31
The SolutionCentralized Logging SystemUses WebServerTraceListenerWrites to web service that stores events in SQL ServerSearch/View for Events via ASP.NET!Client or ServerWebServiceSQLServerASP.NET

More Related Content

What's hot (12)

PDF
Continuous Integration: Live Static Analysis with Puma Scan
Cypress Data Defense
 
PPTX
Robot framework
boriau
 
PPTX
Advanced malwareanalysis training session2 botnet analysis part1
Cysinfo Cyber Security Community
 
PPT
Static Code Analysis and AutoLint
Leander Hasty
 
PDF
26.1.7 lab snort and firewall rules
Freddy Buenaño
 
PDF
25.3.11 packet tracer logging from multiple sources
Freddy Buenaño
 
PDF
27.2.14 lab isolate compromised host using 5-tuple
Freddy Buenaño
 
PPTX
Static Code Analysis
Geneva, Switzerland
 
PPTX
Buffer overflow attacks
Japneet Singh
 
PPTX
Code samples that actually compile - Clare Macrae
Clare Macrae
 
PPTX
Server Side Template Injection by Mandeep Jadon
Mandeep Jadon
 
PDF
Half-automatic Compilable Source Code Recovery
Joxean Koret
 
Continuous Integration: Live Static Analysis with Puma Scan
Cypress Data Defense
 
Robot framework
boriau
 
Advanced malwareanalysis training session2 botnet analysis part1
Cysinfo Cyber Security Community
 
Static Code Analysis and AutoLint
Leander Hasty
 
26.1.7 lab snort and firewall rules
Freddy Buenaño
 
25.3.11 packet tracer logging from multiple sources
Freddy Buenaño
 
27.2.14 lab isolate compromised host using 5-tuple
Freddy Buenaño
 
Static Code Analysis
Geneva, Switzerland
 
Buffer overflow attacks
Japneet Singh
 
Code samples that actually compile - Clare Macrae
Clare Macrae
 
Server Side Template Injection by Mandeep Jadon
Mandeep Jadon
 
Half-automatic Compilable Source Code Recovery
Joxean Koret
 

Similar to Back-2-Basics: Exception & Event Instrumentation in .NET (20)

PPTX
Eventlog
Shashi Kanth
 
PPTX
Logging tracing and metrics in .NET Core and Azure - dotnetdays 2020
Alex Thissen
 
PPTX
Logging, tracing and metrics: Instrumentation in .NET 5 and Azure
Alex Thissen
 
PPTX
Production Debugging at Code Camp Philly
Brian Lyttle
 
PPT
.NET Debugging Workshop
Sasha Goldshtein
 
PPTX
About .net
joeyparkker
 
PPTX
Semantic Logging: Avoiding the Logging Chaos
Christopher Bennage
 
PPTX
CodeFest 2014. Christopher Bennage — Semantic Logging. Avoiding the log chaos
CodeFest
 
PPT
Dot Net Framework
ssa2010
 
PPT
.NET Debugging Tips and Techniques
Bala Subra
 
PPT
.Net Debugging Techniques
Bala Subra
 
PPTX
Debugging NET Applications With WinDBG
Cory Foy
 
PPTX
Campus days 2013 - Instrumentation
Anders Lybecker
 
PPTX
Back-2-Basics: .NET Coding Standards For The Real World
David McCarter
 
PPTX
News In The Net40
Florin Cardasim
 
PPTX
Back-2-Basics: .NET Coding Standards For The Real World
David McCarter
 
PPT
NNUG Certification Presentation
Niall Merrigan
 
PPTX
ReflectInsight - Let your application speak volume
Callon Campbell
 
PPTX
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
David Wengier
 
ODP
(7) c sharp introduction_advanvced_features_part_ii
Nico Ludwig
 
Eventlog
Shashi Kanth
 
Logging tracing and metrics in .NET Core and Azure - dotnetdays 2020
Alex Thissen
 
Logging, tracing and metrics: Instrumentation in .NET 5 and Azure
Alex Thissen
 
Production Debugging at Code Camp Philly
Brian Lyttle
 
.NET Debugging Workshop
Sasha Goldshtein
 
About .net
joeyparkker
 
Semantic Logging: Avoiding the Logging Chaos
Christopher Bennage
 
CodeFest 2014. Christopher Bennage — Semantic Logging. Avoiding the log chaos
CodeFest
 
Dot Net Framework
ssa2010
 
.NET Debugging Tips and Techniques
Bala Subra
 
.Net Debugging Techniques
Bala Subra
 
Debugging NET Applications With WinDBG
Cory Foy
 
Campus days 2013 - Instrumentation
Anders Lybecker
 
Back-2-Basics: .NET Coding Standards For The Real World
David McCarter
 
News In The Net40
Florin Cardasim
 
Back-2-Basics: .NET Coding Standards For The Real World
David McCarter
 
NNUG Certification Presentation
Niall Merrigan
 
ReflectInsight - Let your application speak volume
Callon Campbell
 
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
David Wengier
 
(7) c sharp introduction_advanvced_features_part_ii
Nico Ludwig
 
Ad

More from David McCarter (16)

PPTX
Röck Yoür Technical Interview - V3
David McCarter
 
PPTX
Rock Your Code With Code Contracts -2013
David McCarter
 
PPTX
Rock Your Code with Code Contracts
David McCarter
 
PDF
.NET Coding Standards For The Real World (2012)
David McCarter
 
PPTX
Back-2-Basics: Code Contracts
David McCarter
 
PPTX
Back-2-Basics: .NET Coding Standards For The Real World (2011)
David McCarter
 
PPTX
How To Survive The Technical Interview
David McCarter
 
PPTX
Real World API Design Using The Entity Framework Services
David McCarter
 
PPTX
Building nTier Applications with Entity Framework Services
David McCarter
 
PPTX
Code Easier With Visual Studio 2010 & Extensions
David McCarter
 
PPTX
Building nTier Applications with Entity Framework Services (Part 2)
David McCarter
 
PPTX
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
PPTX
Back-2-Basics: Exception & Event Instrumentation in .NET
David McCarter
 
PPTX
Building nTier Applications with Entity Framework Services (Part 2)
David McCarter
 
PPTX
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
PPTX
Building N Tier Applications With Entity Framework Services 2010
David McCarter
 
Röck Yoür Technical Interview - V3
David McCarter
 
Rock Your Code With Code Contracts -2013
David McCarter
 
Rock Your Code with Code Contracts
David McCarter
 
.NET Coding Standards For The Real World (2012)
David McCarter
 
Back-2-Basics: Code Contracts
David McCarter
 
Back-2-Basics: .NET Coding Standards For The Real World (2011)
David McCarter
 
How To Survive The Technical Interview
David McCarter
 
Real World API Design Using The Entity Framework Services
David McCarter
 
Building nTier Applications with Entity Framework Services
David McCarter
 
Code Easier With Visual Studio 2010 & Extensions
David McCarter
 
Building nTier Applications with Entity Framework Services (Part 2)
David McCarter
 
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
Back-2-Basics: Exception & Event Instrumentation in .NET
David McCarter
 
Building nTier Applications with Entity Framework Services (Part 2)
David McCarter
 
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
Building N Tier Applications With Entity Framework Services 2010
David McCarter
 
Ad

Recently uploaded (20)

PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 

Back-2-Basics: Exception & Event Instrumentation in .NET

  • 1. Back-2-Basics: Exception & Event Instrumentation in .NET
  • 2. 2
  • 3. Check Out Your Local User Groups!San Diego Cloud Computing User Groupwww.azureusergroup.com/group/sandiegoazureusergroupSan Diego .NET Developers Groupwww.sddotnetdg.orgSan Diego .NET User Groupwww.sandiegodotnet.comSan Diego SQL Server User Groupwww.sdsqlug.org
  • 4. Win Free Software!RulesProvide your business card (or email and name)*Indicate on the back what software you are interested inOtherwise I will pick Winners will be picked next week*Yes, most likely I’m going to send you and email about my user group (sddotnetdg.org) and or web site (dotNetTips.com)PrizesCodeRush and Refactor Pro from DevExpress (4)SecondCopy (automatic backup software) (5) *CodeIt.Right Standard from SubMain (4)*Requires mailing address and phone number
  • 7. Why Do We Need To?Debugging statements only work in debug builds and while in VSNo way to tell what applications are doing during runtimeNeed to log exceptions for evaluation by support & development teamsNeed to log other information during runtimeLog information for reporting7
  • 8. Logging Methods You Use?Log to Event log?Custom text files?Custom xml files?Database?….
  • 9. The .NET SolutionTrace Listeners!Easy to use from any .NET application including ASP.NET!!Extremely configurableEasy to write your own listeners
  • 11. OverviewWrite informative messages about the execution of an application at run time.PhasesInstrumentation — you add trace code to your application. Tracing — the tracing code writes information to the specified target. Analysis — you evaluate the tracing information to identify and understand problems in the application.11
  • 12. OverviewOutput is written to one to many listeners.Part of the Trace.Listeners collectionOutput Methods:Assert - The specified text; or, if none is specified, the Call Stack. Fail - The specified text; or, if none is specified, the Call Stack.WriteWriteIfWriteLineWriteLineIf
  • 13. Out of the Box ListenersTextWriterTraceListenerWrites to the TextWriter or Steam classEventLogTraceListenerWrites to an event logEvent works with ASP.NET!DefaultTraceListenerWrites Write and WriteLine messages to the OutputDebugString and to the Debugger.Log method (debug window in VS)
  • 14. Out of the Box ListenersConsoleTraceListenerWrites output to the console windowDelimitedListTraceListener Writes to the text writer in a delimited text formatXmlWriterTraceListenerWrites to xml file.
  • 15. ConfigurationDone via code or application config fileTurn off/ on listenersSet trace levelsSet filters
  • 16. Configuration Example<system.diagnostics> <sources> <source name="DefaultSource" switchName="DefaultSwitch"> <listeners> <add name="FileLog"/> </listeners></source></sources><switches> <add name="DefaultSwitch" value="Information" /></switches> <sharedListeners> <add name="FileLog“ type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL“ initializeData="FileLogWriter"/> </sharedListeners></system.diagnostics>
  • 18. Add custom functionality & enhance .NET listenersCustom Trace Listeners
  • 19. OverviewCreate your own listeners or enhance current listenersInherit TraceListenerOverride:Write - writes the specified message to the listener.WriteLine - Writes a message to the listener.TraceEvent - Writes trace information, a message, and event information to the listener specific output.19
  • 20. OverviewOverride:TraceData - Writes trace information, a data object and event information to the listener specific output.GetSupportedAttributes - Gets the custom attributes supported by the trace listener.Add to config fileIn place or in addition to the .NET listeners.20
  • 21. Issues with .NET ListenersXmlWriterTraceListenerDoes not write well formed xmlCreates one huge fileWith ASP.NET it says lockedCan not move, delete etc. Can not view latest trace writesDue to flushing issuesMost other file based listeners most likely suffer from the same issues
  • 22. Taking Exception & Event logging to the extreme!dotNetTips.Utility Listeners
  • 23. OverviewListeners part of the dotNetTips.UtilityOpen source project available at http://codeplex.com/dotnettipsCurrent version requires .NET 3.5Fixes/ enhances .NET ListenersAdds new ListenersOutputs A LOT more debugging info!Add custom information during runtime!Built-in configuration!23
  • 24. Advanced Debugging InfoVia the LogEntry classAutomatic when logging Exceptions:Tread/ Process informationDomain nameApplication informationUser informationComputer informationAuto log class and method where Exception happenedMuch more!
  • 25. More on LogEntryAdd custom information into a collectionAdditional propertiesCategoryId (GUID)UserMachineNameSeveritySourceSourceVersion
  • 26. Enhanced ListenersEventLogTraceListenersXmlTraceListenersFixes all issues of the .NET implementation!Writes well formed xml!Does not lock file!Creates a new file for each dayAutomatic delete of old files (configurable)
  • 27. Added ListenersEmailTraceListenerEmail trace events via smtp serverWebServiceTraceListenerSends trace events to a web service methodTCPTraceListener (coming soon)Sends trace events to TCP listenersWatch events in real time!
  • 28. Writing Exceptions/ EventsUse LogWriterCustom for logging Exceptions, Events and LogEntryLogging Exceptions and Events uses LogEntry under the hoodWrites to the correct log collection based on type of applicationMethodsWriteEntryMessages (events) and LogEntryWriteException
  • 30. Lets Kick It Up A Notch!Centralized Logging System
  • 31. The ProblemEach client/ server machine logs locallySupport has to logon to each machine to read eventsNot possible sometimes at client locationNo search capabilitiesServerServerServerLogFileLogFileLogFileServerServerServerLogFileLogFileLogFile31
  • 32. The SolutionCentralized Logging SystemUses WebServerTraceListenerWrites to web service that stores events in SQL ServerSearch/View for Events via ASP.NET!Client or ServerWebServiceSQLServerASP.NET
  • 34. SummaryUse TraceListeners to log Exceptions/ Events!Use my Centralized Logging SystemdotNetTips.Utility (codeplex.com/dotnettips)ASP.NET site/ database (dotNetTips.com)Also look into the Enterprise LibraryLots more then just logging

Editor's Notes

  • #9: ASK AUDIENCE BEFORE SHOWING LIST.Do you have issues with file logging with ASP.NET??
  • #12: Briefly discuss the difference between Debug and Tracing.When you create a distributed application, you might find it difficult to test the application in the manner in which it will be used. Few development teams have the capability to test all possible combinations of operating systems or Web browsers (including all the localized language options), or to simulate the high number of users that will access the application at the same time. Under these circumstances, you cannot test how a distributed application will respond to high volumes, different setups, and unique end-user behaviors. Also, many parts of a distributed application have no user interface with which you can interact directly or view the activity of those parts.However, you can compensate for this by enabling distributed applications to describe certain events of interest to system administrators, especially things that go wrong, by instrumenting the application — that is, by placing trace statements at strategic locations in your code. Then if something unexpected occurs at run time (for example, excessively slow response time), you can determine the likely cause.