-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add LoggingGenerator #51064
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 LoggingGenerator #51064
Changes from 1 commit
71cf1eb
afd85ab
fe21a95
b6281b5
ca3ead4
470b160
515f029
6affdd8
7f15797
8b3cdaa
1c0e756
5893090
56943dd
056e81c
b72ec2d
4ab2acc
0718293
d065c90
d99cec0
b31bca8
1a4e336
128f5d2
3740b68
e275551
fc8ce48
951f5cc
bf36548
b773ce8
6b25016
1eb4e9f
bb45336
e979d5f
c459d32
14530de
d0ebfb2
6354e8f
8ece920
0167f30
9915bbd
43f671c
66310a1
58709eb
11b5ef1
da8099b
dd39eba
a93b5c0
17d3a5b
561dbf3
8f94d10
34d2237
6fabebc
438f2bb
3fd97a1
9c6c08b
71fd60a
4424c8b
bb33d1c
c89bb35
755f3ff
225b63d
139e5bb
e8db38a
5e3d279
00cac9b
9e150d9
83eb36e
cc44192
b611bbd
60fef62
79dc2d4
055cf3f
abb5010
9087427
58b3369
82f1611
bb63032
5f210fc
fe54581
407a9e8
b1f5364
3afda5f
b7b2928
c41c463
3ef2083
a7eba74
ba71c47
4cb1466
daf1a7a
3a97c73
946f764
80840e6
5637b69
0cc8316
1297f11
2add7ce
13631d2
d9970f7
d809dad
dd51c53
70f24ef
afb43d7
2d41c6d
7e68b1c
9200131
6a71553
7547f38
6eab93d
cc0bb07
e56d447
b970fdd
bd93ccf
a6ecab3
35a584c
0ec16c4
e81015d
1b7a158
d94e42f
a2f18d9
e110684
ba9b77f
843c0f3
65b1f51
c0c22ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Fix build on csproj - Make InternalsVisibleTo in test for DiagDescriptors asserts - Fix name typos in sln and cs file
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
|
|
||
| [assembly: InternalsVisibleTo("Microsoft.Extensions.Logging.Generators.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] | ||
maryamariyan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ public enum ActivityTrackingOptions | |
| TraceState = 8, | ||
| TraceFlags = 16, | ||
| Tags = 32, | ||
| Baggage = 64 | ||
| Baggage = 64, | ||
| } | ||
| public static partial class FilterLoggingBuilderExtensions | ||
| { | ||
|
|
@@ -85,6 +85,15 @@ public LoggerFilterRule(string providerName, string categoryName, Microsoft.Exte | |
| public string ProviderName { get { throw null; } } | ||
| public override string ToString() { throw null; } | ||
| } | ||
| [System.AttributeUsageAttribute(System.AttributeTargets.Method)] | ||
| public sealed partial class LoggerMessageAttribute : System.Attribute | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is still up in the air - but I assumed we weren't putting the attribute in the library's
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to file an issue on roslyn to help solve this. I think this generator is a great case study to drive such an issue. Especially given that in Preview4 the reference assembly will be in the ASP.NETCore shared framework but the generator will only be in the NuGet package.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A way to do this would be to provide an analyzer that validates if the corresponding partial-implementation part is there, and errors if it is not. If that's a requirement of this attribute, it should be responsible for delivering the analyzer that validates that piece IMO.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just about to reply with your message here @CyrusNajmabadi :) you beat me to it.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What if the analyzer isn't passed to the compiler? That's just the same problem. I don't think adding redundancy in another optional component is a solution. |
||
| { | ||
| public LoggerMessageAttribute() { } | ||
| public int EventId { get { throw null; } set { } } | ||
| public string? EventName { get { throw null; } set { } } | ||
| public Microsoft.Extensions.Logging.LogLevel Level { get { throw null; } set { } } | ||
| public string Message { get { throw null; } set { } } | ||
| } | ||
| public static partial class LoggingBuilderExtensions | ||
| { | ||
| public static Microsoft.Extensions.Logging.ILoggingBuilder AddProvider(this Microsoft.Extensions.Logging.ILoggingBuilder builder, Microsoft.Extensions.Logging.ILoggerProvider provider) { throw null; } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Extensions.Logging | ||
| { | ||
| /// <summary> | ||
| /// Provides information to guide the production of a strongly-typed logging method. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Method)] | ||
| public sealed class LoggerMessageAttribute : Attribute | ||
| { | ||
| #pragma warning disable SA1629 // Documentation text should end with a period | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="LoggerMessageAttribute"/> class | ||
| /// which is used to guide the production of a strongly-typed logging method. | ||
| /// </summary> | ||
| /// <remarks> | ||
maryamariyan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// The method this attribute is applied to: | ||
| /// - Must be a partial method. | ||
| /// - Must return <c>void</c>. | ||
| /// - Must not be generic. | ||
| /// - Must have an <see cref="ILogger"/> as one of its parameters. | ||
| /// - Must have a <see cref="Microsoft.Extensions.Logging.LogLevel"/> as one of its parameters. | ||
| /// - None of the parameters can be generic. | ||
| /// </remarks> | ||
| /// <example> | ||
| /// static partial class Log | ||
| /// { | ||
| /// [LoggerMessage(EventId = 0, Message = "Could not open socket for {hostName}")] | ||
| /// static partial void CouldNotOpenSocket(ILogger logger, LogLevel level, string hostName); | ||
| /// } | ||
| /// </example> | ||
| public LoggerMessageAttribute() { } | ||
| #pragma warning restore SA1629 // Documentation text should end with a period | ||
|
|
||
| /// <summary> | ||
| /// Gets the logging event id for the logging method. | ||
| /// </summary> | ||
| public int EventId { get; set; } = -1; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the logging event name for the logging method. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This will equal the method name if not specified. | ||
| /// </remarks> | ||
| public string? EventName { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the logging level for the logging method. | ||
| /// </summary> | ||
| public LogLevel Level { get; set; } = LogLevel.None; | ||
|
|
||
| /// <summary> | ||
| /// Gets the message text for the logging method. | ||
| /// </summary> | ||
| public string Message { get; set; } = ""; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.