Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
| __`SYSLIB1025`__ | Multiple logging methods cannot use the same event name within a class |
| __`SYSLIB1026`__ | C# language version not supported by the logging source generator. |
| __`SYSLIB1027`__ | Primary constructor parameter of type Microsoft.Extensions.Logging.ILogger is hidden by a field |
| __`SYSLIB1028`__ | _`SYSLIB1001`-`SYSLIB1029` reserved for logging._ |
| __`SYSLIB1028`__ | Argument is using the unsupported params parameter modifier |
| __`SYSLIB1029`__ | _`SYSLIB1001`-`SYSLIB1029` reserved for logging._ |
| __`SYSLIB1030`__ | JsonSourceGenerator did not generate serialization metadata for type |
| __`SYSLIB1031`__ | JsonSourceGenerator encountered a duplicate JsonTypeInfo property name |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,13 @@ public static class DiagnosticDescriptors
category: "LoggingGenerator",
DiagnosticSeverity.Info,
isEnabledByDefault: true);

public static DiagnosticDescriptor InvalidLoggingMethodParameterParams { get; } = DiagnosticDescriptorHelper.Create(
Comment thread
tarekgh marked this conversation as resolved.
id: "SYSLIB1028",
title: new LocalizableResourceString(nameof(SR.InvalidLoggingMethodParameterParamsTitle), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
messageFormat: new LocalizableResourceString(nameof(SR.InvalidLoggingMethodParameterParamsMessage), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
category: "LoggingGenerator",
DiagnosticSeverity.Error,
isEnabledByDefault: true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ private void GenParameters(LoggerMethod lm)
_builder.Append(", ");
}

if (p.IsScoped)
{
_builder.Append("scoped ");
}
if (p.Qualifier != null)
{
_builder.Append($"{p.Qualifier} ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,22 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt
keepMethod = false;
break;
}
else if (paramSymbol.RefKind == (RefKind)4) // RefKind.RefReadOnlyParameter, added in Roslyn 4.8
Comment thread
tarekgh marked this conversation as resolved.
{
qualifier = "ref readonly";
}

string typeName = paramTypeSymbol.ToDisplayString(
SymbolDisplayFormat.FullyQualifiedFormat.WithMiscellaneousOptions(
SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier));

if (paramSymbol.IsParams)
Comment thread
tarekgh marked this conversation as resolved.
{
Diag(DiagnosticDescriptors.InvalidLoggingMethodParameterParams, paramSymbol.Locations[0], paramName);
keepMethod = false;
break;
}

var lp = new LoggerParameter
{
Name = paramName,
Expand All @@ -382,6 +393,9 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt
IsLogLevel = !foundLogLevel && IsBaseOrIdentity(paramTypeSymbol, _logLevelSymbol, sm.Compilation),
IsEnumerable = IsBaseOrIdentity(paramTypeSymbol, _enumerableSymbol, sm.Compilation) && !IsBaseOrIdentity(paramTypeSymbol, _stringSymbol, sm.Compilation),
};
#if ROSLYN4_4_OR_GREATER
lp.IsScoped = paramSymbol.ScopedKind != ScopedKind.None;
#endif

foundLogger |= lp.IsLogger;
foundException |= lp.IsException;
Expand Down Expand Up @@ -1021,6 +1035,9 @@ internal sealed class LoggerParameter
public bool IsException;
public bool IsLogLevel;
public bool IsEnumerable;
#pragma warning disable CS0649 // Field is never assigned to in builds without ROSLYN4_4_OR_GREATER
public bool IsScoped;
#pragma warning restore CS0649
// A parameter flagged as IsTemplateParameter is not going to be taken care of specially as an argument to ILogger.Log
// but instead is supposed to be taken as a parameter for the template.
public bool IsTemplateParameter => !IsLogger && !IsException && !IsLogLevel;
Expand All @@ -1034,7 +1051,8 @@ internal sealed class LoggerParameter
IsLogger = IsLogger,
IsException = IsException,
IsLogLevel = IsLogLevel,
IsEnumerable = IsEnumerable
IsEnumerable = IsEnumerable,
IsScoped = IsScoped
};
}

Expand All @@ -1051,6 +1069,7 @@ internal sealed record LoggerParameterSpec : IEquatable<LoggerParameterSpec>
public required bool IsException { get; init; }
public required bool IsLogLevel { get; init; }
public required bool IsEnumerable { get; init; }
public required bool IsScoped { get; init; }

// A parameter flagged as IsTemplateParameter is not going to be taken care of specially as an argument to ILogger.Log
// but instead is supposed to be taken as a parameter for the template.
Expand All @@ -1067,7 +1086,8 @@ public bool Equals(LoggerParameterSpec? other)
IsLogger == other.IsLogger &&
IsException == other.IsException &&
IsLogLevel == other.IsLogLevel &&
IsEnumerable == other.IsEnumerable;
IsEnumerable == other.IsEnumerable &&
IsScoped == other.IsScoped;
}

public override int GetHashCode()
Expand All @@ -1080,6 +1100,7 @@ public override int GetHashCode()
hash = HashHelpers.Combine(hash, IsException.GetHashCode());
hash = HashHelpers.Combine(hash, IsLogLevel.GetHashCode());
hash = HashHelpers.Combine(hash, IsEnumerable.GetHashCode());
hash = HashHelpers.Combine(hash, IsScoped.GetHashCode());
return hash;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ private static LoggerClass FromSpec(LoggerClassSpec spec)
IsLogger = paramSpec.IsLogger,
IsException = paramSpec.IsException,
IsLogLevel = paramSpec.IsLogLevel,
IsEnumerable = paramSpec.IsEnumerable
IsEnumerable = paramSpec.IsEnumerable,
IsScoped = paramSpec.IsScoped
Comment thread
tarekgh marked this conversation as resolved.
Outdated
});
}

Expand All @@ -245,7 +246,8 @@ private static LoggerClass FromSpec(LoggerClassSpec spec)
IsLogger = paramSpec.IsLogger,
IsException = paramSpec.IsException,
IsLogLevel = paramSpec.IsLogLevel,
IsEnumerable = paramSpec.IsEnumerable
IsEnumerable = paramSpec.IsEnumerable,
IsScoped = paramSpec.IsScoped
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,10 @@
<value>Primary constructor parameter of type Microsoft.Extensions.Logging.ILogger is hidden by a field</value>
<comment>{Locked="Microsoft.Extensions.Logging.ILogger"}</comment>
</data>
<data name="InvalidLoggingMethodParameterParamsMessage" xml:space="preserve">
<value>Argument '{0}' is using the unsupported params parameter modifier</value>
</data>
<data name="InvalidLoggingMethodParameterParamsTitle" xml:space="preserve">
<value>Argument is using the unsupported params parameter modifier</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">Šablona protokolování nemá žádný odpovídající argument metody</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">Protokollierungsvorlage weist kein entsprechendes Methodenargument auf</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">La plantilla de registro no tiene ningún argumento de método correspondiente</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">Le modèle de journalisation n’a pas d’argument de méthode correspondant</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">Il modello di registrazione non ha alcun argomento del metodo corrispondente</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">ログ テンプレートに対応するメソッド引数がありません</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">로깅 템플릿에 해당 하는 메서드 인수가 없음</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">Szablon rejestrowania nie ma odpowiadającego mu argumentu metody</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">O modelo de registro em log não tem nenhum argumento de método correspondente</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">У шаблона журнала нет соответствующего аргумента метода</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">Günlüğe kaydetme şablonunda karşılık gelen yöntem bağımsız değişkeni yok</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">日志记录模板无相应的方法参数</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@
<target state="translated">記錄範本沒有對應的方法引數</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsMessage">
<source>Argument '{0}' is using the unsupported params parameter modifier</source>
<target state="new">Argument '{0}' is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
<trans-unit id="InvalidLoggingMethodParameterParamsTitle">
<source>Argument is using the unsupported params parameter modifier</source>
<target state="new">Argument is using the unsupported params parameter modifier</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Loading
Loading