Skip to content

Commit

Permalink
Suppress logging checks in hot query paths
Browse files Browse the repository at this point in the history
Part of #23611
  • Loading branch information
roji committed Apr 17, 2021
1 parent d39bb8f commit d9a4482
Show file tree
Hide file tree
Showing 50 changed files with 3,453 additions and 2,168 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.Diagnostics
{
/// <summary>
/// An <see cref="IDiagnosticsLogger{ConnectionCategory}" /> with some extra functionality suited for high-performance logging.
/// </summary>
public interface IRelationalConnectionDiagnosticsLogger : IDiagnosticsLogger<DbLoggerCategory.Database.Connection>
{
/// <summary>
/// Logs for the <see cref="RelationalEventId.ConnectionOpening" /> event.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="startTime"> The time that the operation was started. </param>
/// <returns> The result of execution, which may have been modified by an interceptor. </returns>
InterceptionResult ConnectionOpening(
IRelationalConnection connection,
DateTimeOffset startTime);

/// <summary>
/// Logs for the <see cref="RelationalEventId.ConnectionOpening" /> event.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="startTime"> The time that the operation was started. </param>
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
/// <returns> A <see cref="Task" /> representing the async operation. </returns>
/// <exception cref="OperationCanceledException"> If the <see cref="CancellationToken"/> is canceled. </exception>
ValueTask<InterceptionResult> ConnectionOpeningAsync(
IRelationalConnection connection,
DateTimeOffset startTime,
CancellationToken cancellationToken);

/// <summary>
/// Logs for the <see cref="RelationalEventId.ConnectionOpened" /> event.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="startTime"> The time that the operation was started. </param>
/// <param name="duration"> The amount of time before the connection was opened. </param>
void ConnectionOpened(
IRelationalConnection connection,
DateTimeOffset startTime,
TimeSpan duration);

/// <summary>
/// Logs for the <see cref="RelationalEventId.ConnectionOpened" /> event.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="startTime"> The time that the operation was started. </param>
/// <param name="duration"> The amount of time before the connection was opened. </param>
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
/// <returns> A <see cref="Task" /> representing the async operation. </returns>
/// <exception cref="OperationCanceledException"> If the <see cref="CancellationToken"/> is canceled. </exception>
Task ConnectionOpenedAsync(
IRelationalConnection connection,
DateTimeOffset startTime,
TimeSpan duration,
CancellationToken cancellationToken = default);

/// <summary>
/// Logs for the <see cref="RelationalEventId.ConnectionClosing" /> event.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="startTime"> The time that the operation was started. </param>
/// <returns> The result of execution, which may have been modified by an interceptor. </returns>
InterceptionResult ConnectionClosing(
IRelationalConnection connection,
DateTimeOffset startTime);

/// <summary>
/// Logs for the <see cref="RelationalEventId.ConnectionClosing" /> event.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="startTime"> The time that the operation was started. </param>
/// <returns> A <see cref="Task" /> representing the async operation. </returns>
ValueTask<InterceptionResult> ConnectionClosingAsync(
IRelationalConnection connection,
DateTimeOffset startTime);

/// <summary>
/// Logs for the <see cref="RelationalEventId.ConnectionClosed" /> event.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="startTime"> The time that the operation was started. </param>
/// <param name="duration"> The amount of time before the connection was closed. </param>
void ConnectionClosed(
IRelationalConnection connection,
DateTimeOffset startTime,
TimeSpan duration);

/// <summary>
/// Logs for the <see cref="RelationalEventId.ConnectionClosed" /> event.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="startTime"> The time that the operation was started. </param>
/// <param name="duration"> The amount of time before the connection was closed. </param>
/// <returns> A <see cref="Task" /> representing the async operation. </returns>
Task ConnectionClosedAsync(
IRelationalConnection connection,
DateTimeOffset startTime,
TimeSpan duration);

/// <summary>
/// Logs for the <see cref="RelationalEventId.ConnectionError" /> event.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="exception"> The exception representing the error. </param>
/// <param name="startTime"> The time that the operation was started. </param>
/// <param name="duration"> The elapsed time before the operation failed. </param>
/// <param name="logErrorAsDebug"> A flag indicating the exception is being handled and so it should be logged at Debug level. </param>
void ConnectionError(
IRelationalConnection connection,
Exception exception,
DateTimeOffset startTime,
TimeSpan duration,
bool logErrorAsDebug);

/// <summary>
/// Logs for the <see cref="RelationalEventId.ConnectionError" /> event.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="exception"> The exception representing the error. </param>
/// <param name="startTime"> The time that the operation was started. </param>
/// <param name="duration"> The elapsed time before the operation failed. </param>
/// <param name="logErrorAsDebug"> A flag indicating the exception is being handled and so it should be logged at Debug level. </param>
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
/// <returns> A <see cref="Task" /> representing the async operation. </returns>
/// <exception cref="OperationCanceledException"> If the <see cref="CancellationToken"/> is canceled. </exception>
Task ConnectionErrorAsync(
IRelationalConnection connection,
Exception exception,
DateTimeOffset startTime,
TimeSpan duration,
bool logErrorAsDebug,
CancellationToken cancellationToken = default);

/// <summary>
/// Whether <see cref="RelationalEventId.ConnectionOpening" /> or <see cref="RelationalEventId.ConnectionOpened" /> need
/// to be logged.
/// </summary>
bool ShouldLogConnectionOpen(DateTimeOffset now);

/// <summary>
/// Whether <see cref="RelationalEventId.ConnectionClosing" /> or <see cref="RelationalEventId.ConnectionClosed" /> need
/// to be logged.
/// </summary>
bool ShouldLogConnectionClose(DateTimeOffset now);
}
}
Loading

0 comments on commit d9a4482

Please sign in to comment.