Skip to content

Commit

Permalink
Stop generating DiagnosticSource events for purely design-time messages
Browse files Browse the repository at this point in the history
This means if the message is in "Scaffolding", then it is tested to not generate DiagnosticSource events.

All other events are tested to be doing DiagnosticSource messages using nominal types.

Issue #7939
  • Loading branch information
ajcvickers committed Jun 6, 2017
1 parent f47ad95 commit 1ad8007
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 679 deletions.
219 changes: 44 additions & 175 deletions src/EFCore.Design/Internal/DesignLoggerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
// 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.Globalization;
using System.Linq;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Design;
using Microsoft.EntityFrameworkCore.Migrations.Internal;
using Microsoft.EntityFrameworkCore.Migrations.Operations;

namespace Microsoft.EntityFrameworkCore.Internal
{
Expand All @@ -26,233 +20,108 @@ public static class DesignLoggerExtensions
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void MissingSchemaWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string schemaName)
{
var definition = DesignStrings.LogMissingSchema;

definition.Log(diagnostics, schemaName);

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new
{
SchemaName = schemaName
});
}
}
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string schemaName)
// No DiagnosticsSource events because these are purely design-time messages
=> DesignStrings.LogMissingSchema.Log(diagnostics, schemaName);

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void SequenceTypeNotSupportedWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string sequenceName,
[CanBeNull] string dataTypeName)
{
var definition = DesignStrings.LogBadSequenceType;

definition.Log(diagnostics, sequenceName, dataTypeName);

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new
{
SequenceName = sequenceName,
DataTypeName = dataTypeName
});
}
}
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string sequenceName,
[CanBeNull] string dataTypeName)
// No DiagnosticsSource events because these are purely design-time messages
=> DesignStrings.LogBadSequenceType.Log(diagnostics, sequenceName, dataTypeName);

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void UnableToGenerateEntityTypeWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string tableName)
{
var definition = DesignStrings.LogUnableToGenerateEntityType;

definition.Log(diagnostics, tableName);

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new
{
TableName = tableName
});
}
}
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string tableName)
// No DiagnosticsSource events because these are purely design-time messages
=> DesignStrings.LogUnableToGenerateEntityType.Log(diagnostics, tableName);

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void ColumnTypeNotMappedWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string columnName,
[CanBeNull] string dataTypeName)
{
var definition = DesignStrings.LogCannotFindTypeMappingForColumn;

definition.Log(diagnostics, columnName, dataTypeName);

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new
{
ColumnName = columnName,
DataTypeName = dataTypeName
});
}
}
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string columnName,
[CanBeNull] string dataTypeName)
// No DiagnosticsSource events because these are purely design-time messages
=> DesignStrings.LogCannotFindTypeMappingForColumn.Log(diagnostics, columnName, dataTypeName);

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void MissingPrimaryKeyWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string tableName)
{
var definition = DesignStrings.LogMissingPrimaryKey;

definition.Log(diagnostics, tableName);

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new
{
TableName = tableName
});
}
}
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string tableName)
// No DiagnosticsSource events because these are purely design-time messages
=> DesignStrings.LogMissingPrimaryKey.Log(diagnostics, tableName);

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void PrimaryKeyColumnsNotMappedWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string tableName,
[NotNull] IList<string> unmappedColumnNames)
{
var definition = DesignStrings.LogPrimaryKeyErrorPropertyNotFound;

definition.Log(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string tableName,
[NotNull] IList<string> unmappedColumnNames)
// No DiagnosticsSource events because these are purely design-time messages
=> DesignStrings.LogPrimaryKeyErrorPropertyNotFound.Log(
diagnostics,
tableName,
string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, unmappedColumnNames));

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new
{
TableName = tableName,
UnmappedColumnNames = unmappedColumnNames
});
}
}

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void ForeignKeyReferencesNotMappedTableWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string foreignKeyName,
[NotNull] string principalTableName)
{
var definition = DesignStrings.LogForeignKeyScaffoldErrorPrincipalTableScaffoldingError;

definition.Log(diagnostics, foreignKeyName, principalTableName);

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new
{
ForeignKeyName = foreignKeyName,
PrincipalTableName = principalTableName
});
}
}
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string foreignKeyName,
[NotNull] string principalTableName)
// No DiagnosticsSource events because these are purely design-time messages
=> DesignStrings.LogForeignKeyScaffoldErrorPrincipalTableScaffoldingError.Log(diagnostics, foreignKeyName, principalTableName);

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void ForeignKeyReferencesMissingPrincipalKeyWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string foreignKeyName,
[CanBeNull] string principalEntityTypeName,
[NotNull] IList<string> principalColumnNames)
{
var definition = DesignStrings.LogForeignKeyScaffoldErrorPrincipalKeyNotFound;

definition.Log(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string foreignKeyName,
[CanBeNull] string principalEntityTypeName,
[NotNull] IList<string> principalColumnNames)
// No DiagnosticsSource events because these are purely design-time messages
=> DesignStrings.LogForeignKeyScaffoldErrorPrincipalKeyNotFound.Log(
diagnostics,
foreignKeyName,
string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, principalColumnNames),
principalEntityTypeName);

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new
{
ForeignKeyName = foreignKeyName,
PrincipalEntityTypeName = principalEntityTypeName,
PrincipalColumnNames = principalColumnNames
});
}
}

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static void ForeignKeyPrincipalEndContainsNullableColumnsWarning(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string foreignKeyName,
[CanBeNull] string indexName,
[CanBeNull] IList<string> nullablePropertyNames)
{
var definition = DesignStrings.LogForeignKeyPrincipalEndContainsNullableColumns;

definition.Log(
[NotNull] this IDiagnosticsLogger<DbLoggerCategory.Scaffolding> diagnostics,
[CanBeNull] string foreignKeyName,
[CanBeNull] string indexName,
[CanBeNull] IList<string> nullablePropertyNames)
// No DiagnosticsSource events because these are purely design-time messages
=> DesignStrings.LogForeignKeyPrincipalEndContainsNullableColumns.Log(
diagnostics,
foreignKeyName,
indexName,
nullablePropertyNames.Aggregate((a, b) => a + "," + b));

if (diagnostics.DiagnosticSource.IsEnabled(definition.EventId.Name))
{
diagnostics.DiagnosticSource.Write(
definition.EventId.Name,
new
{
ForeignKeyName = foreignKeyName,
IndexName = indexName,
NullablePropertyNames = nullablePropertyNames
});
}
}
}
}
Loading

0 comments on commit 1ad8007

Please sign in to comment.