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

Enable CA1810 as a warning #40384

Merged
merged 1 commit into from
Feb 25, 2022
Merged

Enable CA1810 as a warning #40384

merged 1 commit into from
Feb 25, 2022

Conversation

pranavkm
Copy link
Contributor

Contributes to #24055
Contributes to #32087

  • This updates most of the repo to use LoggerMessageAttributes. MvcCoreLoggerExtensions is the only standout but it is fairly involved since it mixes logging from several types, re-uses logger ids etc

@Pilchie Pilchie added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Feb 24, 2022
using System.Diagnostics;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Mvc.Razor;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly all of the log messages on this types, except the one you see in the previous file, had been moved to individual types over time, and hence weren't referenced.

@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
#pragma warning disable CA1810 // Initialize all static fields inline.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try and do do this separately. The source generator does not like that we reuse ids.

$"{nameof(ResourceManagerStringLocalizer)} searched for '{{Key}}' in '{{LocationSearched}}' with culture '{{Culture}}'.");
}

public static void SearchedLocation(this ILogger logger, string key, string searchedLocation, CultureInfo culture)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this to ResourceManagerStringLocalizer in the file below.

@@ -53,5 +38,15 @@ static Diagnostics()
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
helpLinkUri: "https://aka.ms/AA64fv1");

public static readonly ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics = ImmutableArray.Create<DiagnosticDescriptor>(new[]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static fields are initialized in the order in which they appear, but you can reference them before they are initialized. Cool new thing I found out today.

@pranavkm pranavkm merged commit 1852bb7 into dotnet:main Feb 25, 2022
@pranavkm pranavkm deleted the CA1810 branch February 25, 2022 02:08
@ghost ghost added this to the 7.0-preview3 milestone Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants