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
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,11 @@ static bool IsAllowedKind(SyntaxKind kind) =>
return Array.Empty<LoggerClass>();
}

results.Sort((lhs, rhs) =>
{
int c = StringComparer.Ordinal.Compare(lhs.Namespace, rhs.Namespace);
return c != 0 ? c : StringComparer.Ordinal.Compare(lhs.Name, rhs.Name);
});
return results;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// <auto-generated/>
#nullable enable

namespace Microsoft.Extensions.Logging.Generators.Tests.TestClasses
{
partial class ClassA
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "%VERSION%")]
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Exception?> __LogACallback =
global::Microsoft.Extensions.Logging.LoggerMessage.Define(global::Microsoft.Extensions.Logging.LogLevel.Debug, new global::Microsoft.Extensions.Logging.EventId(1, nameof(LogA)), "Message from ClassA", new global::Microsoft.Extensions.Logging.LogDefineOptions() { SkipEnabledCheck = true });

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "%VERSION%")]
static partial void LogA(global::Microsoft.Extensions.Logging.ILogger logger)
{
if (logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Debug))
{
__LogACallback(logger, null);
}
}
}
}
namespace Microsoft.Extensions.Logging.Generators.Tests.TestClasses
{
partial class ClassB
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "%VERSION%")]
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Exception?> __LogBCallback =
global::Microsoft.Extensions.Logging.LoggerMessage.Define(global::Microsoft.Extensions.Logging.LogLevel.Information, new global::Microsoft.Extensions.Logging.EventId(2, nameof(LogB)), "Message from ClassB", new global::Microsoft.Extensions.Logging.LogDefineOptions() { SkipEnabledCheck = true });

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "%VERSION%")]
static partial void LogB(global::Microsoft.Extensions.Logging.ILogger logger)
{
if (logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Information))
{
__LogBCallback(logger, null);
}
}
}
}
namespace Microsoft.Extensions.Logging.Generators.Tests.TestClasses
{
partial class ClassC
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "%VERSION%")]
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Exception?> __LogCCallback =
global::Microsoft.Extensions.Logging.LoggerMessage.Define(global::Microsoft.Extensions.Logging.LogLevel.Warning, new global::Microsoft.Extensions.Logging.EventId(3, nameof(LogC)), "Message from ClassC", new global::Microsoft.Extensions.Logging.LogDefineOptions() { SkipEnabledCheck = true });

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "%VERSION%")]
static partial void LogC(global::Microsoft.Extensions.Logging.ILogger logger)
{
if (logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Warning))
{
__LogCCallback(logger, null);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,31 @@ internal class Class2 { }
await VerifyAgainstBaselineUsingFile("TestWithNestedClass.generated.txt", testSourceCode);
}

[Fact]
public async Task TestBaseline_TestWithMultipleClassesStableOrder_Success()
{
string testSourceCode = @"
namespace Microsoft.Extensions.Logging.Generators.Tests.TestClasses
{
internal static partial class ClassC
{
[LoggerMessage(EventId = 3, Level = LogLevel.Warning, Message = ""Message from ClassC"")]
static partial void LogC(ILogger logger);
}
internal static partial class ClassA
{
[LoggerMessage(EventId = 1, Level = LogLevel.Debug, Message = ""Message from ClassA"")]
static partial void LogA(ILogger logger);
}
internal static partial class ClassB
{
[LoggerMessage(EventId = 2, Level = LogLevel.Information, Message = ""Message from ClassB"")]
static partial void LogB(ILogger logger);
}
}";
await VerifyAgainstBaselineUsingFile("TestWithMultipleClassesStableOrder.generated.txt", testSourceCode);
}

#if ROSLYN4_0_OR_GREATER
[Fact]
public async Task TestBaseline_TestWithFileScopedNamespace_Success()
Expand Down