SlideShare a Scribd company logo
Logging, tracing and metrics
Overview of instrumentation
in .NET 5 and Azure
Alex Thissen
@alexthissen
Cloud architect at Xpirit, The Netherlands
DevOps needs monitoring
https://docs.microsoft.com/en-us/azure/architecture/checklist/dev-ops#monitoring
Loops in DevOps practices
Application performance monitoring
Cloud applications are complex
Mostly distributed applications
Using multiple cloud resources
Collect and correlate
instrumentation data
Events, usage, metrics, performance, telemetry, logs, traces, health
Sentry.io
Raygun.io Runscope
NewRelic AlertSite DataDog
AppMetrics Azure Monitor
Cloud Application
Azure Resources
Azure Monitor
Azure Subscription
Azure Tenant
Azure Monitor Logs
Applications in Azure
Azure Monitor
Metrics
Collect Monitor
Application instrumentation
Logging
Tracing
Metrics
Health
Dashboards
Alerting
Analytics
Profiling
Metrics
streaming
Choosing correct type of instrumentation
Log
• What
happened?
• Errors and
warnings and
state changes
• Important
state changes
worth
registering
• Always logged
Trace
• How did it
happen?
• Circumstantial
data for
following flow
• Available on
request
• Publish/
subscribe
model mostly
• High volume
Metric
• How much is
happening?
• Numerical
information of
events
• Suitable for
aggregation
and trends
Health
• How is it
doing?
• Information
indicating
health status
• Internally
determined by
component
Audit
• Who made it
happen?
• Data
regarding
actions
performed by
someone
• Always
• Security and
identity
related
• Proof for non-
repudiability
Logging in .NET 5
Leveraging CoreFX libraries
for logging
Logging
Persisting important events in a log
Built-in since .NET Core 1.0
Used internally by CoreFX libraries
Bootstrapping changed from .NET Core 3.0 forward
Logging providers
Host.CreateDefaultBuilder(args)
.ConfigureLogging((context, builder) =>
{
// Log providers
builder.AddApplicationInsights(options =>
{
options.IncludeScopes = true;
options.TrackExceptionsAsExceptionTelemetry = true;
});
builder.AddConsole(options => {
options.Format = ConsoleLoggerFormat.Systemd;
});
builder.AddDebug();
builder.AddTraceSource(source.Switch,
new ApplicationInsightsTraceListener());
.NET 5 * Added by default
NullLoggerProvider
BatchingLoggerProvider
ConsoleLoggerProvider *
DebugLoggerProvider *
EventLogLoggerProvider
EventSourceLoggerProvider *
TraceSourceLoggerProvider
ASP
.NET Core
ApplicationInsightsLoggerProvider
AzureAppServicesFile
AzureAppServicesBlob
Third party
NLogLogger
Seq
Log4Net
Loggr
LoggerFactory and logger instances
LoggerFactory
LogCritical
LogError
LogWarning
LogDebug
LogTrace
LogInformation
ILogger<T>
Log severity levels and categories
Hierarchical structure
Much like namespaces in C#, separated by dots
Microsoft
Microsoft.Hosting.Lifetime
Determined from T in ILogger<T>
Except when creating ILogger directly with LoggerFactory.CreateLogger
public enum LogLevel
{
Trace = 0,
Debug = 1,
Information = 2,
Warning = 3,
Error = 4,
Critical = 5,
None = 6
}
ILogger<LeaderboardController>
namespace LeaderboardWebApi.Controllers {
public class LeaderboardController : Controller { … }
}
"LeaderboardWebApi.Controllers.LeaderboardController"
Separate configuration
for specific providers
General configuration
for all providers
Log filters
Filter log messages
By provider and per log category based on severity
Can read filters from configuration (appsettings.json)
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"Console": {
"LogLevel": { … }
"IncludeScopes": true
}
}
ILogger<T>
Demo
Logging 101
Quantum physics applied to logging
Duality of log messages
Semantic logging (aka structured logging)
Message templates
Strings with named placeholders for semantics
Avoid string interpolation in messages
Popular log providers supporting semantic logging
// Placeholders in template become queryable custom data
logger.LogInformation("Searching with {SearchLimit} results.", limit);
Demo
Structured logging using Seq
Scopes
Groups a set of logical operations
Requires setting options to include scope for provider
logging.AddConsole(options => options.IncludeScopes = true);
using (logger.BeginScope("Message attached to logs created in the using block"))
{
logger.LogInformation(LoggingEvents.NewHighScore, “New high score {score}", highScore);
var game = gameRepository.Find(gameId);
if (game == null)
{
logger.LogWarning(LoggingEvents.GameNotFound, "GetById({game}) not found", gameId);
return NotFound();
}
}
Logging guidance
Separation of concerns
“A twelve-factor app never concerns itself with routing or storage of its output stream."
Choose your log severity level carefully
You might get paged during the night
Use event IDs when possible
Log messages are not for UI
No need to localize your messages
When in doubt, be generous on logging
Tooling will help you filter and aggregate
Alternative logging solutions
Serilog
Popular open source logging framework
Many log providers available
Replaces built-in logging system
Can also log to .NET log providers
More functionality
Log appenders (aka enrichers) for additional data
Large set of providers
Serilog
Tracing
Familiar concepts and API
from .NET Framework
Diagnostics Trace
High volume noise to follow flow
Not a log of things that happened
Publish/subscribe
Requires a listener to receive information
Information not persisted unless subscribed
System.Diagnostics namespace
Trace and TraceSource entrypoints
Needs compilation constant #TRACE
Uses activities under the cover
Tracing infrastructure
Trace
“Singleton” with static methods
Traditional tracing
TraceData
TraceEvent
TraceInformation
TraceTransfer
TraceError
TraceWarning
TraceInformation
Write(If)
WriteLine(If)
TraceSource
Activities
Ambient contextual data
Accessible from Activity.Current
Thread-safe and async aware
Used for correlating events
Even across network calls
New W3C tracing format
Application Insights uses activities
Parent/Child relationship
var activity = new Activity("SearchEngine.Run");
activity.SetStartTime(DateTime.Now);
activity.Start();
activity.Track...();
Available trace listeners
Namespace Class .NET version
System.Diagnostics DefaultTraceListener Core 1.0+
TextWriterTraceListener Core 1.0+
EventLogTraceListener Core 3.0
ConsoleTraceListener Core 3.0
DelimitedListTraceListener Core 1.0+
XmlWriterTraceListener Core 3.0
EventSchemaTraceListener .NET FX 3.5+
System.Diagnostics.Eventing EventProviderTraceListener .NET FX 3.5+
System.Web IisTraceListener .NET FX 2.0+
WebPageTraceListener .NET FX 2.0+
Microsoft.VisualBasic.Logging FileLogTraceListener .NET FX 2.0+
From .NET Framework 2.0 to .NET Core 3.0 to .NET 5
Demo
Tracing 101
Health checks
Indicating health status
from .NET 5
Health monitoring
services
.AddHealthChecks()
.AddCheck("sync", () => … )
.AddAsyncCheck("async", async () => … )
.AddCheck<SqlConnectionHealthCheck>("SQL")
.AddCheck<UrlHealthCheck>("URL");
ASP
.NET Core application
/health
DefaultHealthCheckService
Health check publishers
Pushes out health
info periodically
Options
ASP
.NET Core application
DefaultHealthCheckService
HealthCheckPublisher
HostedService
IEnumerable<IHealthCheckPublisher>
services.AddHealthChecks()
.AddApplicationInsightsPublisher()
.AddPrometheusGatewayPublisher(
"http://pushgateway:9091/metrics",
"pushgateway") IHealthCheckPublisher
Probing containers to check for availability and health
Readiness and liveness
Kubernetes node
Kubernetes node
Kubernetes nodes
Containers
Readiness
Liveliness
Implementing readiness and liveliness
1. Add health checks with tags
2. Register multiple endpoints
with filter using
Options predicate
/api/v1/…
/health
/health/ready
/health/lively
app.UseHealthChecks("/health/ready",
new HealthCheckOptions() {
Predicate = reg => reg.Tags.Contains("ready")
});
services.AddHealthChecks()
.AddCheck<CircuitBreakerHealthCheck>(
"circuitbreakers",
tags: new string[] { "ready" });
app.UseHealthChecks("/health/lively",
new HealthCheckOptions() {
Predicate = _ => true
});
Demo
Health checks and monitoring in ASP
.NET Core
Application Insights
Metrics, monitoring, querying
and analyzing your
application
DevOps and loops
Azure Application Insights
Extensible Application Performance Monitor
Application Insights in .NET 5
Logging and tracing
Regular logging provider
Special TraceListener
builder.AddApplicationInsights(options => {
options.TrackExceptionsAsExceptionTelemetry = true;
options.IncludeScopes = true;
});
Telemetry
TelemetryClient StartOperation TrackEvent
Trace.Listeners.Add(new ApplicationInsightsTraceListener());
services.AddApplicationInsightsTelemetry(options =>
{
options.DeveloperMode = true;
});
Demo
Application Insights
DevOps needs monitoring
https://docs.microsoft.com/en-us/azure/architecture/checklist/dev-ops#monitoring
Questions and
answers
Resources
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-5.0
https://docs.microsoft.com/en-us/azure/architecture/patterns/health-endpoint-monitoring
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks
https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks
https://dev.applicationinsights.io/apiexplorer/metrics
https://github.com/alexthissen/instrumentation

More Related Content

What's hot (20)

PDF
API for Beginners
Gustavo De Vita
 
PDF
Sql Injection - Vulnerability and Security
Sandip Chaudhari
 
PDF
webservice scaling for newbie
DaeMyung Kang
 
PPTX
Introduction to EJB
Return on Intelligence
 
PPTX
Azure Functions.pptx
YachikaKamra
 
PPTX
Azure Logic Apps
BizTalk360
 
PPTX
Rest API Security
Stormpath
 
PPT
Data race
James Wong
 
PDF
WEB DEVELOPMENT USING REACT JS
MuthuKumaran Singaravelu
 
PDF
REST APIs with Spring
Joshua Long
 
PPTX
JSON
Zara Tariq
 
PPTX
Secure coding practices
Scott Hurrey
 
PPTX
Spring Framework
tola99
 
PPTX
Enterprise single sign on
Archit Sharma
 
PDF
Programmazione funzionale e Stream in Java
Cristina Attori
 
PDF
Introduction to SOAP/WSDL Web Services and RESTful Web Services
ecosio GmbH
 
ODP
Introduction to Swagger
Knoldus Inc.
 
PDF
Service Worker Presentation
Kyle Dorman
 
PPTX
Who is BIRT
Raghavan Mohan
 
PDF
Introduction to API
rajnishjha29
 
API for Beginners
Gustavo De Vita
 
Sql Injection - Vulnerability and Security
Sandip Chaudhari
 
webservice scaling for newbie
DaeMyung Kang
 
Introduction to EJB
Return on Intelligence
 
Azure Functions.pptx
YachikaKamra
 
Azure Logic Apps
BizTalk360
 
Rest API Security
Stormpath
 
Data race
James Wong
 
WEB DEVELOPMENT USING REACT JS
MuthuKumaran Singaravelu
 
REST APIs with Spring
Joshua Long
 
Secure coding practices
Scott Hurrey
 
Spring Framework
tola99
 
Enterprise single sign on
Archit Sharma
 
Programmazione funzionale e Stream in Java
Cristina Attori
 
Introduction to SOAP/WSDL Web Services and RESTful Web Services
ecosio GmbH
 
Introduction to Swagger
Knoldus Inc.
 
Service Worker Presentation
Kyle Dorman
 
Who is BIRT
Raghavan Mohan
 
Introduction to API
rajnishjha29
 

Similar to Logging, tracing and metrics: Instrumentation in .NET 5 and Azure (20)

PDF
Microservices observability
Maxim Shelest
 
PPT
Enterprise Library 2.0
Raju Permandla
 
PPTX
Setting Up Sumo Logic - Apr 2017
Sumo Logic
 
PDF
I Can See Clearly Now - Observing & understanding your Spring applications at...
Joris Kuipers
 
PDF
Observability foundations in dynamically evolving architectures
Boyan Dimitrov
 
PPT
Application Hosting
webhostingguy
 
PPTX
Setting up Sumo Logic - June 2017
Sumo Logic
 
PDF
Apache Eagle at Hadoop Summit 2016 San Jose
Hao Chen
 
PDF
Apache Eagle: Secure Hadoop in Real Time
DataWorks Summit/Hadoop Summit
 
PPTX
Setting Up Sumo Logic - Sep 2017
mariosany
 
PDF
Empower your security practitioners with the Elastic Stack
Elasticsearch
 
PPT
Enterprise Library 3.0 Overview
mcgurk
 
PDF
XCube-overview-brochure-revB
Richard Jaenicke
 
PPTX
Play framework : A Walkthrough
mitesh_sharma
 
PDF
Apache Eagle Architecture Evolvement
Hao Chen
 
PPTX
Graph The Planet 2019 - Intrusion Detection with Graphs
Matt Swann
 
PDF
Detection as Code, Automation, and Testing: The Key to Unlocking the Power of...
MITRE ATT&CK
 
PPTX
TechEd NZ 2014: Intelligent Systems Service - Concept, Code and Demo
Intergen
 
PDF
Oscar Cabanillas - Elastic - OSL19
marketingsyone
 
PPTX
Apache Eagle in Action
Hao Chen
 
Microservices observability
Maxim Shelest
 
Enterprise Library 2.0
Raju Permandla
 
Setting Up Sumo Logic - Apr 2017
Sumo Logic
 
I Can See Clearly Now - Observing & understanding your Spring applications at...
Joris Kuipers
 
Observability foundations in dynamically evolving architectures
Boyan Dimitrov
 
Application Hosting
webhostingguy
 
Setting up Sumo Logic - June 2017
Sumo Logic
 
Apache Eagle at Hadoop Summit 2016 San Jose
Hao Chen
 
Apache Eagle: Secure Hadoop in Real Time
DataWorks Summit/Hadoop Summit
 
Setting Up Sumo Logic - Sep 2017
mariosany
 
Empower your security practitioners with the Elastic Stack
Elasticsearch
 
Enterprise Library 3.0 Overview
mcgurk
 
XCube-overview-brochure-revB
Richard Jaenicke
 
Play framework : A Walkthrough
mitesh_sharma
 
Apache Eagle Architecture Evolvement
Hao Chen
 
Graph The Planet 2019 - Intrusion Detection with Graphs
Matt Swann
 
Detection as Code, Automation, and Testing: The Key to Unlocking the Power of...
MITRE ATT&CK
 
TechEd NZ 2014: Intelligent Systems Service - Concept, Code and Demo
Intergen
 
Oscar Cabanillas - Elastic - OSL19
marketingsyone
 
Apache Eagle in Action
Hao Chen
 
Ad

More from Alex Thissen (18)

PPTX
Go (con)figure - Making sense of .NET configuration
Alex Thissen
 
PPTX
Health monitoring and dependency injection - CNUG November 2019
Alex Thissen
 
PPTX
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
Alex Thissen
 
PPTX
I dont feel so well. Integrating health checks in your .NET Core solutions - ...
Alex Thissen
 
PPTX
It depends: Loving .NET Core dependency injection or not
Alex Thissen
 
PPTX
Overview of the new .NET Core and .NET Platform Standard
Alex Thissen
 
PPTX
Exploring Microservices in a Microsoft Landscape
Alex Thissen
 
PPTX
How Docker and ASP.NET Core will change the life of a Microsoft developer
Alex Thissen
 
PPTX
Visual Studio Productivity tips
Alex Thissen
 
PPTX
Exploring microservices in a Microsoft landscape
Alex Thissen
 
PPTX
Asynchronous programming in ASP.NET
Alex Thissen
 
PPTX
Visual Studio 2015 experts tips and tricks
Alex Thissen
 
PPTX
ASP.NET 5 - Microsoft's Web development platform reimagined
Alex Thissen
 
PPTX
MVC 6 - the new unified Web programming model
Alex Thissen
 
PPTX
//customer/
Alex Thissen
 
PPTX
ASP.NET vNext
Alex Thissen
 
PPTX
Run your Dockerized ASP.NET application on Windows and Linux!
Alex Thissen
 
PPTX
.NET Core: a new .NET Platform
Alex Thissen
 
Go (con)figure - Making sense of .NET configuration
Alex Thissen
 
Health monitoring and dependency injection - CNUG November 2019
Alex Thissen
 
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
Alex Thissen
 
I dont feel so well. Integrating health checks in your .NET Core solutions - ...
Alex Thissen
 
It depends: Loving .NET Core dependency injection or not
Alex Thissen
 
Overview of the new .NET Core and .NET Platform Standard
Alex Thissen
 
Exploring Microservices in a Microsoft Landscape
Alex Thissen
 
How Docker and ASP.NET Core will change the life of a Microsoft developer
Alex Thissen
 
Visual Studio Productivity tips
Alex Thissen
 
Exploring microservices in a Microsoft landscape
Alex Thissen
 
Asynchronous programming in ASP.NET
Alex Thissen
 
Visual Studio 2015 experts tips and tricks
Alex Thissen
 
ASP.NET 5 - Microsoft's Web development platform reimagined
Alex Thissen
 
MVC 6 - the new unified Web programming model
Alex Thissen
 
//customer/
Alex Thissen
 
ASP.NET vNext
Alex Thissen
 
Run your Dockerized ASP.NET application on Windows and Linux!
Alex Thissen
 
.NET Core: a new .NET Platform
Alex Thissen
 
Ad

Recently uploaded (20)

PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PDF
Dealing with JSON in the relational world
Andres Almiray
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
Dealing with JSON in the relational world
Andres Almiray
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 

Logging, tracing and metrics: Instrumentation in .NET 5 and Azure

Editor's Notes

  • #3: https://docs.microsoft.com/en-us/azure/architecture/checklist/dev-ops#monitoring
  • #6: For activity logs and diagnostics: Log Analytics workspace for analyzing Azure Storage for archiving Event Hub for streaming
  • #10: Photo by Matthias Groeneveld from Pexels
  • #18: https://blogs.msdn.microsoft.com/webdev/2017/04/26/asp-net-core-logging/
  • #25: Located in System.Diagnostics.TraceSource How to: Create and Initialize Trace Sources | Microsoft Docs
  • #34: How can restarting a container instance solve health?
  • #37: Photo by Dan Lohmar on Unsplash
  • #42: https://docs.microsoft.com/en-us/azure/architecture/checklist/dev-ops#monitoring