Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EventId, LogLevel, and message generation for event payloads #8637

Merged
merged 1 commit into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 135 additions & 30 deletions src/EFCore.Design/Diagnostics/DesignEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,92 +45,197 @@ private enum Id
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="DbLoggerCategory.Migrations" /> category.
/// <para>
/// Removing a migration without checking the database.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="MigrationDesignEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId MigrationForceRemove = MakeMigrationsId(Id.MigrationForceRemove);

/// <summary>
/// Removing migration.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// Removing migration.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="MigrationDesignEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId MigrationRemoving = MakeMigrationsId(Id.MigrationRemoving);

/// <summary>
/// A migration file was not found.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// A migration file was not found.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="MigrationFileNameEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId MigrationFileNotFound = MakeMigrationsId(Id.MigrationFileNotFound);

/// <summary>
/// A metadata file was not found.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// A metadata file was not found.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="MigrationFileNameEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId MigrationMetadataFileNotFound = MakeMigrationsId(Id.MigrationMetadataFileNotFound);

/// <summary>
/// A manual migration deletion was detected.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// A manual migration deletion was detected.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="MigrationDesignEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId MigrationManuallyDeleted = MakeMigrationsId(Id.MigrationManuallyDeleted);

/// <summary>
/// Removing model snapshot.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// Removing model snapshot.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="ModelSnapshotFileNameEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId SnapshotRemoving = MakeMigrationsId(Id.SnapshotRemoving);

/// <summary>
/// No model snapshot file named was found.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// No model snapshot file named was found.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="ModelSnapshotFileNameEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId SnapshotFileNotFound = MakeMigrationsId(Id.SnapshotFileNotFound);

/// <summary>
/// Writing model snapshot to file.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// Writing model snapshot to file.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="ScaffoldedMigrationEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId SnapshotWriting = MakeMigrationsId(Id.SnapshotWriting);

/// <summary>
/// Reusing namespace of a type.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// Reusing namespace of a type.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="ResourceReusedEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId NamespaceReusing = MakeMigrationsId(Id.NamespaceReusing);

/// <summary>
/// Reusing directory for a file.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// Reusing directory for a file.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="ResourceReusedEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId DirectoryReusing = MakeMigrationsId(Id.DirectoryReusing);

/// <summary>
/// Reverting model snapshot.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// Reverting model snapshot.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="ModelSnapshotFileNameEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId SnapshotReverting = MakeMigrationsId(Id.SnapshotReverting);

/// <summary>
/// Writing migration to file.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// Writing migration to file.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="ScaffoldedMigrationEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId MigrationWriting = MakeMigrationsId(Id.MigrationWriting);

/// <summary>
/// Resuing model snapshot name.
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// <para>
/// Resuing model snapshot name.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="SnapshotNameEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </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="DbLoggerCategory.Migrations" /> category.
/// <para>
/// An operation was scaffolded that may result in the loss of data. Please review the migration for accuracy.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="MigrationOperationsEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </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="DbLoggerCategory.Migrations" /> category.
/// <para>
/// The namespace contains migrations for a different context.
/// </para>
/// <para>
/// This event is in the <see cref="DbLoggerCategory.Migrations" /> category.
/// </para>
/// <para>
/// This event uses the <see cref="NamespaceEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </summary>
public static readonly EventId ForeignMigrations = MakeMigrationsId(Id.ForeignMigrations);
}
Expand Down
37 changes: 37 additions & 0 deletions src/EFCore.Design/Diagnostics/MigrationDesignEventData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Microsoft.EntityFrameworkCore.Diagnostics
{
/// <summary>
/// A <see cref="DiagnosticSource" /> event payload class for events that have
/// an associated <see cref="Migrations.Migration" />.
/// </summary>
public class MigrationDesignEventData : EventDataBase
{
/// <summary>
/// Constructs the event payload.
/// </summary>
/// <param name="eventDefinition"> The event definition. </param>
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
/// <param name="migration"> The <see cref="Migration" />. </param>
public MigrationDesignEventData(
[NotNull] EventDefinitionBase eventDefinition,
[NotNull] Func<EventDefinitionBase, EventDataBase, string> messageGenerator,
[NotNull] Migration migration)
: base(eventDefinition, messageGenerator)
{
Migration = migration;
}

/// <summary>
/// The <see cref="Migration" />.
/// </summary>
public virtual Migration Migration { get; }
}
}
45 changes: 45 additions & 0 deletions src/EFCore.Design/Diagnostics/MigrationFileNameEventData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Microsoft.EntityFrameworkCore.Diagnostics
{
/// <summary>
/// A <see cref="DiagnosticSource" /> event payload class for events that have
/// an associated <see cref="Migrations.Migration" /> and file name.
/// </summary>
public class MigrationFileNameEventData : EventDataBase
{
/// <summary>
/// Constructs the event payload.
/// </summary>
/// <param name="eventDefinition"> The event definition. </param>
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
/// <param name="migration"> The <see cref="Migration" />. </param>
/// <param name="fileName"> The file name. </param>
public MigrationFileNameEventData(
[NotNull] EventDefinitionBase eventDefinition,
[NotNull] Func<EventDefinitionBase, EventDataBase, string> messageGenerator,
[NotNull] Migration migration,
[NotNull] string fileName)
: base(eventDefinition, messageGenerator)
{
Migration = migration;
FileName = fileName;
}

/// <summary>
/// The <see cref="Migration" />.
/// </summary>
public virtual Migration Migration { get; }

/// <summary>
/// The file name.
/// </summary>
public virtual string FileName { get; }
}
}
38 changes: 38 additions & 0 deletions src/EFCore.Design/Diagnostics/MigrationOperationsEventData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.Collections.Generic;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Migrations.Operations;

namespace Microsoft.EntityFrameworkCore.Diagnostics
{
/// <summary>
/// A <see cref="DiagnosticSource" /> event payload class for events that have
/// associated <see cref="MigrationOperation" />s.
/// </summary>
public class MigrationOperationsEventData : EventDataBase
{
/// <summary>
/// Constructs the event payload.
/// </summary>
/// <param name="eventDefinition"> The event definition. </param>
/// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
/// <param name="operations"> The operations. </param>
public MigrationOperationsEventData(
[NotNull] EventDefinitionBase eventDefinition,
[NotNull] Func<EventDefinitionBase, EventDataBase, string> messageGenerator,
[NotNull] IEnumerable<MigrationOperation> operations)
: base(eventDefinition, messageGenerator)
{
Operations = operations;
}

/// <summary>
/// The operations.
/// </summary>
public virtual IEnumerable<MigrationOperation> Operations { get; }
}
}
Loading