-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update EventIds to be unique and be consistent with ILogger/Diagnosti…
…cSource Issues #218 #6802 (Doesn't cover #6946 - Template-based format strings.) This change introduces unique event IDs and a pattern such that every time an event is logged it is sent to both ILogger and DiagnosticSource. Specifically: * EventIds are globally unique across core/relational/any given provider. (As discussed in #218) * The same EventIds are used for ILogger and DiagnosticSource (ILogger uses the int/name tuple, DiagnosticSource uses just the name) * EventIds align with logger categories * Automated tests for the EventId/LoggerExtensions pattern--every EventId has a LoggerExtension method that works as expected. * Warnings configuration is updated to use the new event ids * Updated IsEnabled to handle warnings as errors and ignored warnings more transparently.
- Loading branch information
1 parent
8e0c0b2
commit 4d96eb0
Showing
156 changed files
with
6,027 additions
and
2,455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,137 @@ | ||
// 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.Diagnostics; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Infrastructure | ||
{ | ||
public enum DesignEventId | ||
/// <summary> | ||
/// <para> | ||
/// Event IDs for design events that correspond to messages logged to an <see cref="ILogger" /> | ||
/// and events sent to a <see cref="DiagnosticSource" />. | ||
/// </para> | ||
/// <para> | ||
/// These IDs are also used with <see cref="WarningsConfigurationBuilder" /> to configure the | ||
/// behavior of warnings. | ||
/// </para> | ||
/// </summary> | ||
public static class DesignEventId | ||
{ | ||
ForceRemoveMigration = 1, | ||
RemovingMigration, | ||
NoMigrationFile, | ||
NoMigrationMetadataFile, | ||
ManuallyDeleted, | ||
RemovingSnapshot, | ||
NoSnapshotFile, | ||
WritingSnapshot, | ||
ReusingNamespace, | ||
ReusingDirectory, | ||
RevertingSnapshot, | ||
WritingMigration, | ||
ReusingSnapshotName, | ||
DestructiveOperation, | ||
ForeignMigrations | ||
// Warning: These values must not change between releases. | ||
// Only add new values to the end of sections, never in the middle. | ||
// Try to use <Noun><Verb> naming and be consistent with existing names. | ||
private enum Id | ||
{ | ||
// Migrations events | ||
MigrationForceRemove = CoreEventId.CoreDesignBaseId, | ||
MigrationRemoving, | ||
MigrationFileNotFound, | ||
MigrationMetadataFileNotFound, | ||
MigrationManuallyDeleted, | ||
SnapshotRemoving, | ||
SnapshotFileNotFound, | ||
SnapshotWriting, | ||
NamespaceReusing, | ||
DirectoryReusing, | ||
SnapshotReverting, | ||
MigrationWriting, | ||
SnapshotNameReusing, | ||
DestructiveOperation, | ||
ForeignMigrations | ||
} | ||
|
||
private static readonly string _migrationsPrefix = LoggerCategory.Migrations.Name + "."; | ||
private static EventId MakeMigrationsId(Id id) => new EventId((int)id, _migrationsPrefix + id); | ||
|
||
/// <summary> | ||
/// Removing a migration without checking the database. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId MigrationForceRemove = MakeMigrationsId(Id.MigrationForceRemove); | ||
|
||
/// <summary> | ||
/// Removing migration. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId MigrationRemoving = MakeMigrationsId(Id.MigrationRemoving); | ||
|
||
/// <summary> | ||
/// A migration file was not found. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId MigrationFileNotFound = MakeMigrationsId(Id.MigrationFileNotFound); | ||
|
||
/// <summary> | ||
/// A metadata file was not found. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId MigrationMetadataFileNotFound = MakeMigrationsId(Id.MigrationMetadataFileNotFound); | ||
|
||
/// <summary> | ||
/// A manual migration deletion was detected. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId MigrationManuallyDeleted = MakeMigrationsId(Id.MigrationManuallyDeleted); | ||
|
||
/// <summary> | ||
/// Removing model snapshot. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId SnapshotRemoving = MakeMigrationsId(Id.SnapshotRemoving); | ||
|
||
/// <summary> | ||
/// No model snapshot file named was found. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId SnapshotFileNotFound = MakeMigrationsId(Id.SnapshotFileNotFound); | ||
|
||
/// <summary> | ||
/// Writing model snapshot to file. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId SnapshotWriting = MakeMigrationsId(Id.SnapshotWriting); | ||
|
||
/// <summary> | ||
/// Reusing namespace of a type. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId NamespaceReusing = MakeMigrationsId(Id.NamespaceReusing); | ||
|
||
/// <summary> | ||
/// Reusing directory for a file. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId DirectoryReusing = MakeMigrationsId(Id.DirectoryReusing); | ||
|
||
/// <summary> | ||
/// Reverting model snapshot. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId SnapshotReverting = MakeMigrationsId(Id.SnapshotReverting); | ||
|
||
/// <summary> | ||
/// Writing migration to file. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId MigrationWriting = MakeMigrationsId(Id.MigrationWriting); | ||
|
||
/// <summary> | ||
/// Resuing model snapshot name. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId SnapshotNameReusing = MakeMigrationsId(Id.SnapshotNameReusing); | ||
|
||
/// <summary> | ||
/// An operation was scaffolded that may result in the loss of data. Please review the migration for accuracy. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId DestructiveOperation = MakeMigrationsId(Id.DestructiveOperation); | ||
|
||
/// <summary> | ||
/// The namespace contains migrations for a different context. | ||
/// This event is in the <see cref="LoggerCategory.Migrations" /> category. | ||
/// </summary> | ||
public static readonly EventId ForeignMigrations = MakeMigrationsId(Id.ForeignMigrations); | ||
} | ||
} |
Oops, something went wrong.