Skip to content
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
10 changes: 5 additions & 5 deletions docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
| __`SYSLIB1022`__ | Can't have malformed format strings (like dangling {, etc) |
| __`SYSLIB1023`__ | Generating more than 6 arguments is not supported |
| __`SYSLIB1024`__ | Argument is using the unsupported out parameter modifier |
| __`SYSLIB1025`__ | *_`SYSLIB1024`-`SYSLIB1029` reserved for logging._* |
| __`SYSLIB1026`__ | *_`SYSLIB1024`-`SYSLIB1029` reserved for logging._* |
| __`SYSLIB1027`__ | *_`SYSLIB1024`-`SYSLIB1029` reserved for logging._* |
| __`SYSLIB1028`__ | *_`SYSLIB1024`-`SYSLIB1029` reserved for logging._* |
| __`SYSLIB1029`__ | *_`SYSLIB1024`-`SYSLIB1029` reserved for logging._* |
| __`SYSLIB1025`__ | Multiple logging methods cannot use the same event name within a class |
| __`SYSLIB1026`__ | *_`SYSLIB1026`-`SYSLIB1029` reserved for logging._* |
| __`SYSLIB1027`__ | *_`SYSLIB1026`-`SYSLIB1029` reserved for logging._* |
| __`SYSLIB1028`__ | *_`SYSLIB1026`-`SYSLIB1029` reserved for logging._* |
| __`SYSLIB1029`__ | *_`SYSLIB1026`-`SYSLIB1029` reserved for logging._* |
| __`SYSLIB1030`__ | JsonSourceGenerator did not generate serialization metadata for type |
| __`SYSLIB1031`__ | JsonSourceGenerator encountered a duplicate JsonTypeInfo property name |
| __`SYSLIB1032`__ | JsonSourceGenerator encountered a context class that is not partial |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,13 @@ public static class DiagnosticDescriptors
category: "LoggingGenerator",
DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static DiagnosticDescriptor ShouldntReuseEventNames { get; } = new DiagnosticDescriptor(
id: "SYSLIB1025",
title: new LocalizableResourceString(nameof(SR.ShouldntReuseEventNamesTitle), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
messageFormat: new LocalizableResourceString(nameof(SR.ShouldntReuseEventNamesMessage), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
category: "LoggingGenerator",
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt
INamedTypeSymbol stringSymbol = _compilation.GetSpecialType(SpecialType.System_String);

var results = new List<LoggerClass>();
var ids = new HashSet<int>();
var eventIds = new HashSet<int>();
var eventNames = new HashSet<string>();

// we enumerate by syntax tree, to minimize the need to instantiate semantic models (since they're expensive)
foreach (var group in classes.GroupBy(x => x.SyntaxTree))
Expand All @@ -84,7 +85,10 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt
string? loggerField = null;
bool multipleLoggerFields = false;

ids.Clear();
// events ids and names should be unique in a class
eventIds.Clear();
eventNames.Clear();

foreach (MemberDeclarationSyntax member in classDec.Members)
{
var method = member as MethodDeclarationSyntax;
Expand Down Expand Up @@ -252,14 +256,16 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt
keepMethod = false;
}

// ensure there are no duplicate ids.
if (ids.Contains(lm.EventId))
// ensure there are no duplicate event ids.
if (!eventIds.Add(lm.EventId))
{
Diag(DiagnosticDescriptors.ShouldntReuseEventIds, ma.GetLocation(), lm.EventId, classDec.Identifier.Text);
}
else

// ensure there are no duplicate event names.
if (lm.EventName != null && !eventNames.Add(lm.EventName))
{
_ = ids.Add(lm.EventId);
Diag(DiagnosticDescriptors.ShouldntReuseEventNames, ma.GetLocation(), lm.EventName, classDec.Identifier.Text);
}

string msg = lm.Message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema

Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple

There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -222,4 +222,10 @@
<data name="InvalidLoggingMethodParameterOutTitle" xml:space="preserve">
<value>Argument is using the unsupported out parameter modifier</value>
</data>
</root>
<data name="ShouldntReuseEventNamesMessage" xml:space="preserve">
<value>Multiple logging methods are using event name {0} in class {1}</value>
</data>
<data name="ShouldntReuseEventNamesTitle" xml:space="preserve">
<value>Multiple logging methods should not use the same event name within a class</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
<target state="translated">Více než jedna metoda protokolování nemůže v rámci třídy používat stejné ID události.</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesMessage">
<source>Multiple logging methods are using event name {0} in class {1}</source>
<target state="new">Multiple logging methods are using event name {0} in class {1}</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesTitle">
<source>Multiple logging methods should not use the same event name within a class</source>
<target state="new">Multiple logging methods should not use the same event name within a class</target>
<note />
</trans-unit>
<trans-unit id="TemplateHasNoCorrespondingArgumentMessage">
<source>Template '{0}' is not provided as argument to the logging method</source>
<target state="translated">Šablona {0} se neposkytuje jako argument pro metodu protokolování.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
<target state="translated">Dieselbe Ereignis-ID kann nicht von mehreren Protokollierungsmethoden innerhalb einer Klasse verwendet werden</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesMessage">
<source>Multiple logging methods are using event name {0} in class {1}</source>
<target state="new">Multiple logging methods are using event name {0} in class {1}</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesTitle">
<source>Multiple logging methods should not use the same event name within a class</source>
<target state="new">Multiple logging methods should not use the same event name within a class</target>
<note />
</trans-unit>
<trans-unit id="TemplateHasNoCorrespondingArgumentMessage">
<source>Template '{0}' is not provided as argument to the logging method</source>
<target state="translated">Die Vorlage „{0}“ wird nicht als Argument für die Protokollierungsmethode bereitgestellt</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
<target state="translated">Varios métodos de registro no pueden usar un mismo id. de evento en una clase</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesMessage">
<source>Multiple logging methods are using event name {0} in class {1}</source>
<target state="new">Multiple logging methods are using event name {0} in class {1}</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesTitle">
<source>Multiple logging methods should not use the same event name within a class</source>
<target state="new">Multiple logging methods should not use the same event name within a class</target>
<note />
</trans-unit>
<trans-unit id="TemplateHasNoCorrespondingArgumentMessage">
<source>Template '{0}' is not provided as argument to the logging method</source>
<target state="translated">La plantilla "{0}" no se proporciona como argumento para el método de registro</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
<target state="translated">Le même ID d’événement dans une classe ne peut pas être utilisé par plusieurs méthodes de journalisation</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesMessage">
<source>Multiple logging methods are using event name {0} in class {1}</source>
<target state="new">Multiple logging methods are using event name {0} in class {1}</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesTitle">
<source>Multiple logging methods should not use the same event name within a class</source>
<target state="new">Multiple logging methods should not use the same event name within a class</target>
<note />
</trans-unit>
<trans-unit id="TemplateHasNoCorrespondingArgumentMessage">
<source>Template '{0}' is not provided as argument to the logging method</source>
<target state="translated">Le modèle « {0} » n’est pas fourni comme argument de la méthode de journalisation</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
<target state="translated">Più metodi di registrazione non possono utilizzare lo stesso ID evento all'interno di una classe</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesMessage">
<source>Multiple logging methods are using event name {0} in class {1}</source>
<target state="new">Multiple logging methods are using event name {0} in class {1}</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesTitle">
<source>Multiple logging methods should not use the same event name within a class</source>
<target state="new">Multiple logging methods should not use the same event name within a class</target>
<note />
</trans-unit>
<trans-unit id="TemplateHasNoCorrespondingArgumentMessage">
<source>Template '{0}' is not provided as argument to the logging method</source>
<target state="translated">Il modello ‘{0}’ non è specificato come argomento per il metodo di registrazione</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
<target state="translated">複数のログ記録方法では、クラス内で同じイベント ID を使用できません</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesMessage">
<source>Multiple logging methods are using event name {0} in class {1}</source>
<target state="new">Multiple logging methods are using event name {0} in class {1}</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesTitle">
<source>Multiple logging methods should not use the same event name within a class</source>
<target state="new">Multiple logging methods should not use the same event name within a class</target>
<note />
</trans-unit>
<trans-unit id="TemplateHasNoCorrespondingArgumentMessage">
<source>Template '{0}' is not provided as argument to the logging method</source>
<target state="translated">テンプレート '{0}' は、ログ メソッドの引数として提供されません</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
<target state="translated">여러 로깅 메서드가 한 클래스 내에서 동일한 이벤트 ID를 사용할 수는 없음</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesMessage">
<source>Multiple logging methods are using event name {0} in class {1}</source>
<target state="new">Multiple logging methods are using event name {0} in class {1}</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesTitle">
<source>Multiple logging methods should not use the same event name within a class</source>
<target state="new">Multiple logging methods should not use the same event name within a class</target>
<note />
</trans-unit>
<trans-unit id="TemplateHasNoCorrespondingArgumentMessage">
<source>Template '{0}' is not provided as argument to the logging method</source>
<target state="translated">템플릿 {0}이(가) 로깅 메서드에 인수로 제공되지 않음</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
<target state="translated">Wiele metod rejestrowania nie może używać tego samego identyfikatora zdarzenia w obrębie klasy</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesMessage">
<source>Multiple logging methods are using event name {0} in class {1}</source>
<target state="new">Multiple logging methods are using event name {0} in class {1}</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesTitle">
<source>Multiple logging methods should not use the same event name within a class</source>
<target state="new">Multiple logging methods should not use the same event name within a class</target>
<note />
</trans-unit>
<trans-unit id="TemplateHasNoCorrespondingArgumentMessage">
<source>Template '{0}' is not provided as argument to the logging method</source>
<target state="translated">Nie podano szablonu „{0}” jako argumentu dla metody rejestrowania</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
<target state="translated">Múltiplos métodos de registro em log não podem usar o mesmo id de evento dentro de uma classe</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesMessage">
<source>Multiple logging methods are using event name {0} in class {1}</source>
<target state="new">Multiple logging methods are using event name {0} in class {1}</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesTitle">
<source>Multiple logging methods should not use the same event name within a class</source>
<target state="new">Multiple logging methods should not use the same event name within a class</target>
<note />
</trans-unit>
<trans-unit id="TemplateHasNoCorrespondingArgumentMessage">
<source>Template '{0}' is not provided as argument to the logging method</source>
<target state="translated">O modelo '{0}' não é fornecido como argumento para o método de registro</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
<target state="translated">Несколько методов ведения журнала не могут использовать одинаковый ИД события в пределах класса</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesMessage">
<source>Multiple logging methods are using event name {0} in class {1}</source>
<target state="new">Multiple logging methods are using event name {0} in class {1}</target>
<note />
</trans-unit>
<trans-unit id="ShouldntReuseEventNamesTitle">
<source>Multiple logging methods should not use the same event name within a class</source>
<target state="new">Multiple logging methods should not use the same event name within a class</target>
<note />
</trans-unit>
<trans-unit id="TemplateHasNoCorrespondingArgumentMessage">
<source>Template '{0}' is not provided as argument to the logging method</source>
<target state="translated">Шаблон "{0}" не указан в качестве аргумента для метода ведения журнала</target>
Expand Down
Loading