Skip to content

Commit

Permalink
Updating for new TOC
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Nov 9, 2020
1 parent 07365ee commit 524bdc5
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ title: Using diagnostic listeners - EF Core
description: Using DiagnosticListener for global consumption of EF Core diagnostics
author: ajcvickers
ms.date: 10/16/2020
uid: core/miscellaneous/events/diagnostics
uid: core/logging-events-diagnostics/diagnostic-listeners
---

# Using diagnostic listeners in EF Core
# Using Diagnostic Listeners in EF Core

> [!TIP]
> You can [download this article's sample](https://github.com/dotnet/EntityFramework.Docs/tree/master/samples/core/Miscellaneous/DiagnosticListeners) from GitHub.
Diagnostic listeners allow listening for any EF Core event that occurs in the current .NET process. The <xref:System.Diagnostics.DiagnosticListener> class is a part of a [common mechanism across .NET](https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md) for obtaining diagnostic information from running applications.

Diagnostic listeners are not suitable for getting events from a single DbContext instance. EF Core [interceptors](xref:core/miscellaneous/events/interception) provide access to the same events with per-context registration.
Diagnostic listeners are not suitable for getting events from a single DbContext instance. EF Core [interceptors](xref:core/logging-events-diagnostics/interceptors) provide access to the same events with per-context registration.

Diagnostic listeners are not designed for logging. Consider using [simple logging](xref:core/miscellaneous/events/simple-logging) or [Microsoft.Extensions.Logging](xref:core/miscellaneous/events/extensions-logging) for logging.
Diagnostic listeners are not designed for logging. Consider using [simple logging](xref:core/logging-events-diagnostics/simple-logging) or [Microsoft.Extensions.Logging](xref:core/logging-events-diagnostics/extensions-logging) for logging.

## Example: Observing diagnostic events

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ title: .NET events - EF Core
description: .NET events defined by EF Core
author: ajcvickers
ms.date: 10/15/2020
uid: core/miscellaneous/events/dotnet-events
uid: core/logging-events-diagnostics/events
---

# .NET events in EF Core

> [!TIP]
> You can [download the events sample](https://github.com/dotnet/EntityFramework.Docs/tree/master/samples/core/Miscellaneous/Events) from GitHub.
Entity Framework Core (EF Core) exposes [.NET events](/dotnet/standard/events/) to act as callbacks when certain things happen in the EF Core code. Events are simpler than [interceptors](xref:core/miscellaneous/events/interception) and allow more flexible registration. However, they are sync only and so cannot perform non-blocking async I/O.
Entity Framework Core (EF Core) exposes [.NET events](/dotnet/standard/events/) to act as callbacks when certain things happen in the EF Core code. Events are simpler than [interceptors](xref:core/logging-events-diagnostics/interceptors) and allow more flexible registration. However, they are sync only and so cannot perform non-blocking async I/O.

Events are registered per `DbContext` instance. Use a [diagnostic listener](xref:core/miscellaneous/events/diagnostics) to get the same information but for all DbContext instances in the process.
Events are registered per `DbContext` instance. Use a [diagnostic listener](xref:core/logging-events-diagnostics/diagnostic-listeners) to get the same information but for all DbContext instances in the process.

## Events raised by EF Core

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ title: Using Microsoft.Extensions.Logging - EF Core
description: Logging from EF Core using Microsoft.Extensions.Logging in ASP.NET Core and other application types
author: ajcvickers
ms.date: 10/15/2020
uid: core/miscellaneous/events/extensions-logging
uid: core/logging-events-diagnostics/extensions-logging
---

# Using Microsoft.Extensions.Logging in EF Core

[Microsoft.Extensions.Logging](/dotnet/core/extensions/logging) is an extensible logging mechanism with plug-in providers for many common logging systems. Both Microsoft-supplied plug-ins (e.g [Microsoft.Extensions.Logging.Console](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Console/)) and third-party plug-ins (e.g. [Serilog.Extensions.Logging](https://www.nuget.org/packages/Serilog.Extensions.Logging/)) are available as NuGet packages.

Entity Framework Core (EF Core) fully integrates with `Microsoft.Extensions.Logging`. However, consider using [simple logging](xref:core/miscellaneous/events/simple-logging) for a simpler way to log, especially for applications that don't use dependency injection.
Entity Framework Core (EF Core) fully integrates with `Microsoft.Extensions.Logging`. However, consider using [simple logging](xref:core/logging-events-diagnostics/simple-logging) for a simpler way to log, especially for applications that don't use dependency injection.

## ASP.NET Core applications

Expand All @@ -20,7 +20,7 @@ Entity Framework Core (EF Core) fully integrates with `Microsoft.Extensions.Logg

Other application types can use the [GenericHost](/dotnet/core/extensions/generic-host) to get the same dependency injection patterns as are used in ASP.NET Core. AddDbContext or AddDbContextPool can then be used just like in ASP.NET Core applications.

`Microsoft.Extensions.Logging` can also be used for applications that don't use dependency injection, although [simple logging](xref:core/miscellaneous/events/simple-logging) can be easier to set up.
`Microsoft.Extensions.Logging` can also be used for applications that don't use dependency injection, although [simple logging](xref:core/logging-events-diagnostics/simple-logging) can be easier to set up.

`Microsoft.Extensions.Logging` requires creation of a <xref:Microsoft.Extensions.Logging.LoggerFactory>. This factory should be stored as a static/global instance somewhere and used each time a DbContext is created. For example, it is common to store the logger factory as a static property on the DbContext.

Expand Down
Empty file.
16 changes: 8 additions & 8 deletions entity-framework/core/logging-events-diagnostics/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ See [Simple Logging](xref:core/logging-events-diagnostics/simple-logging) for mo

EF Core fully integrates with `Microsoft.Extensions.Logging` and this form of logging is used by default for ASP.NET Core applications.

See [Using Microsoft.Extensions.Logging in EF Core](xref:core/miscellaneous/events/extensions-logging) for more information.
See [Using Microsoft.Extensions.Logging in EF Core](xref:core/logging-events-diagnostics/extensions-logging) for more information.

## Events

Expand All @@ -56,9 +56,9 @@ See [Using Microsoft.Extensions.Logging in EF Core](xref:core/miscellaneous/even
EF Core exposes [.NET events](/dotnet/standard/events/) to act as callbacks when certain things happen in the EF Core code. Events are simpler than interceptors and allow more flexible registration. However, they are sync only and so cannot perform non-blocking async I/O.

Events are registered per DbContext instance and this registration can be done at any time. Use a [diagnostic listener](xref:core/miscellaneous/events/diagnostics) to get the same information but for all DbContext instances in the process.
Events are registered per DbContext instance and this registration can be done at any time. Use a [diagnostic listener](xref:core/logging-events-diagnostics/diagnostic-Listeners) to get the same information but for all DbContext instances in the process.

See [.NET Events in EF Core](xref:core/miscellaneous/events/dotnet-events) for more information.
See [.NET Events in EF Core](xref:core/logging-events-diagnostics/events) for more information.

## Interception

Expand All @@ -67,18 +67,18 @@ See [.NET Events in EF Core](xref:core/miscellaneous/events/dotnet-events) for m
EF Core interceptors enable interception, modification, and/or suppression of EF Core events. This includes low-level database operations such as executing a command, as well as higher-level events, such as calls to SaveChanges.

Interceptors are different from logging and diagnostics in that they allow modification or suppression of the operation being intercepted. [Simple logging](xref:core/miscellaneous/events/simple-logging) or [Microsoft.Extensions.Logging](xref:core/miscellaneous/events/extensions-logging) are better choices for logging.
Interceptors are different from logging and diagnostics in that they allow modification or suppression of the operation being intercepted. [Simple logging](xref:core/logging-events-diagnostics/simple-logging) or [Microsoft.Extensions.Logging](xref:core/logging-events-diagnostics/extensions-logging) are better choices for logging.

Interceptors are registered per DbContext instance when the context is configured. Use a [diagnostic listener](xref:core/miscellaneous/events/diagnostics) to get the same information but for all DbContext instances in the process.
Interceptors are registered per DbContext instance when the context is configured. Use a [diagnostic listener](xref:core/logging-events-diagnostics/diagnostic-Listeners) to get the same information but for all DbContext instances in the process.

See [Interception](xref:core/miscellaneous/events/interception) for more information.
See [Interception](xref:core/logging-events-diagnostics/interception) for more information.

## Diagnostic listeners

Diagnostic listeners allow listening for any EF Core event that occurs in the current .NET process.

Diagnostic listeners are not suitable for getting events from a single DbContext instance. EF Core interceptors provide access to the same events with per-context registration.

Diagnostic listeners are not designed for logging. [Simple logging](xref:core/miscellaneous/events/simple-logging) or [Microsoft.Extensions.Logging](xref:core/miscellaneous/events/extensions-logging) are better choices for logging.
Diagnostic listeners are not designed for logging. [Simple logging](xref:core/logging-events-diagnostics/simple-logging) or [Microsoft.Extensions.Logging](xref:core/logging-events-diagnostics/extensions-logging) are better choices for logging.

See [Using diagnostic listeners in EF Core](xref:core/miscellaneous/events/diagnostics) for more information.
See [Using diagnostic listeners in EF Core](xref:core/logging-events-diagnostics/diagnostic-Listeners) for more information.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ title: Interceptors - EF Core
description: Interception for database operations and other events
author: ajcvickers
ms.date: 10/08/2020
uid: core/miscellaneous/events/interception
uid: core/logging-events-diagnostics/interceptors
---

# Interceptors

Entity Framework Core (EF Core) interceptors enable interception, modification, and/or suppression of EF Core events. This includes low-level database operations such as executing a command, as well as higher-level events, such as calls to SaveChanges.

Interceptors are different from logging and diagnostics in that they allow modification or suppression of the operation being intercepted. [Simple logging](xref:core/miscellaneous/events/simple-logging) or [Microsoft.Extensions.Logging](xref:core/miscellaneous/events/extensions-logging) are better choices for logging.
Interceptors are different from logging and diagnostics in that they allow modification or suppression of the operation being intercepted. [Simple logging](xref:core/logging-events-diagnostics/simple-logging) or [Microsoft.Extensions.Logging](xref:core/logging-events-diagnostics/extensions-logging) are better choices for logging.

Interceptors are registered per DbContext instance when the context is configured. Use a [diagnostic listener](xref:core/miscellaneous/events/diagnostics) to get the same information but for all DbContext instances in the process.
Interceptors are registered per DbContext instance when the context is configured. Use a [diagnostic listener](xref:core/logging-events-diagnostics/diagnostic-listeners) to get the same information but for all DbContext instances in the process.

## Registering interceptors

Expand Down Expand Up @@ -394,7 +394,7 @@ Notice from the log output that the application continues to use the cached mess
<xref:Microsoft.EntityFrameworkCore.DbContext.SaveChanges%2A> and <xref:Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync%2A> interception points are defined by the `ISaveChangesInterceptor` <!-- Issue #2748 --> interface. As for other interceptors, the `SaveChangesInterceptor` <!-- Issue #2748 --> base class with no-op methods is provided as a convenience.

> [!TIP]
> Interceptors are powerful. However, in many cases it may be easier to override the SaveChanges method or use the [.NET events for SaveChanges](xref:core/miscellaneous/events/dotnet-events) exposed on DbContext.
> Interceptors are powerful. However, in many cases it may be easier to override the SaveChanges method or use the [.NET events for SaveChanges](xref:core/logging-events-diagnostics/events) exposed on DbContext.
### Example: SaveChanges interception for auditing

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ uid: core/logging-events-diagnostics/simple-logging
Entity Framework Core (EF Core) simple logging can be used to easily obtain logs while developing and debugging applications. This form of logging requires minimal configuration and no additional NuGet packages.

> [!TIP]
> EF Core also integrates with [Microsoft.Extensions.Logging](xref:core/miscellaneous/events/extensions-logging), which requires more configuration, but is often more suitable for logging in production applications.
> EF Core also integrates with [Microsoft.Extensions.Logging](xref:core/logging-events-diagnostics/extensions-logging), which requires more configuration, but is often more suitable for logging in production applications.
## Configuration

Expand Down
12 changes: 8 additions & 4 deletions entity-framework/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,15 @@
href: core/logging-events-diagnostics/index.md
- name: Simple logging
href: core/logging-events-diagnostics/simple-logging.md
#- name: Microsoft.Extensions.Logging
- name: Microsoft.Extensions.Logging
href: core/logging-events-diagnostics/extensions-logging.md
#- name: ToQueryString
#- name: Events
#- name: Interceptors
#- name: Diagnostic listeners
- name: Events
href: core/logging-events-diagnostics/events.md
- name: Interceptors
href: core/logging-events-diagnostics/interceptos.md
- name: Diagnostic listeners
href: core/logging-events-diagnostics/diagnostic-listeners.md
#- name: Debug views
#- name: Event counters

Expand Down

0 comments on commit 524bdc5

Please sign in to comment.