Skip to content

Commit 48913f9

Browse files
committed
uses microsoft logging
Migrates to Microsoft.Extensions.Logging for logging abstraction. This change removes the custom logging infrastructure and replaces it with the standard Microsoft logging. This provides better integration with other .NET libraries and frameworks and allows for more flexible configuration and management of logging.
1 parent 66f823f commit 48913f9

File tree

20 files changed

+60
-92
lines changed

20 files changed

+60
-92
lines changed

new-cli/GitVersion.Calculation/CalculateCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using GitVersion.Extensions;
22
using GitVersion.Git;
3-
using GitVersion.Infrastructure;
3+
using Microsoft.Extensions.Logging;
44

55
namespace GitVersion.Commands;
66

new-cli/GitVersion.Cli.Generator.Tests/GitVersion.Cli.Generator.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<ItemGroup>
99
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
10+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
1011
<PackageReference Include="System.CommandLine" />
1112

1213
<PackageReference Include="Microsoft.CSharp" />

new-cli/GitVersion.Cli.Generator.Tests/SystemCommandlineGeneratorTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.CodeAnalysis.CSharp.Testing;
66
using Microsoft.CodeAnalysis.Testing;
77
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Logging;
89

910
namespace GitVersion.Cli.Generator.Tests;
1011

@@ -13,7 +14,8 @@ public class SystemCommandlineGeneratorTests
1314
/*language=cs*/
1415
private const string TestCommandSourceCode =
1516
$$"""
16-
using {{Content.DependencyInjectionNamespaceName}};
17+
using {{Content.InfrastructureNamespaceName}};
18+
using Microsoft.Extensions.Logging;
1719
1820
namespace {{Content.CommandNamespaceName}};
1921
@@ -95,9 +97,9 @@ Task<int> Run(ParseResult parseResult, CancellationToken cancellationToken)
9597
$$"""
9698
{{Content.GeneratedHeader}}
9799
using System.CommandLine;
98-
using {{Content.DependencyInjectionNamespaceName}};
100+
using {{Content.InfrastructureNamespaceName}};
99101
using {{Content.CommandNamespaceName}};
100-
using {{Content.InfraNamespaceName}};
102+
using {{Content.CommonNamespaceName}};
101103
using Microsoft.Extensions.DependencyInjection;
102104
103105
namespace {{Content.GeneratedNamespaceName}};
@@ -119,7 +121,7 @@ public void RegisterTypes(IServiceCollection services)
119121
{{Content.GeneratedHeader}}
120122
using System.CommandLine;
121123
122-
using {{Content.InfraNamespaceName}};
124+
using {{Content.CommonNamespaceName}};
123125
namespace {{Content.GeneratedNamespaceName}};
124126
125127
public class RootCommandImpl : RootCommand
@@ -173,6 +175,7 @@ public async Task ValidateGeneratedCommandImplementation()
173175
MetadataReference.CreateFromFile(typeof(IServiceCollection).Assembly.Location),
174176
MetadataReference.CreateFromFile(typeof(RootCommand).Assembly.Location),
175177
MetadataReference.CreateFromFile(typeof(CommandAttribute).Assembly.Location),
178+
MetadataReference.CreateFromFile(typeof(IGitVersionModule).Assembly.Location),
176179
}
177180
}
178181
};

new-cli/GitVersion.Cli.Generator/CommandBaseGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ namespace GitVersion;
44

55
public abstract class CommandBaseGenerator : IIncrementalGenerator
66
{
7-
private const string CommandInterfaceFullName = $"{Content.InfraNamespaceName}.ICommand<T>";
8-
private const string CommandAttributeFullName = $"{Content.InfraNamespaceName}.CommandAttribute";
9-
private const string CommandAttributeGenericFullName = $"{Content.InfraNamespaceName}.CommandAttribute<T>";
10-
private const string OptionAttributeFullName = $"{Content.InfraNamespaceName}.OptionAttribute";
7+
private const string CommandInterfaceFullName = $"{Content.CommonNamespaceName}.ICommand<T>";
8+
private const string CommandAttributeFullName = $"{Content.CommonNamespaceName}.CommandAttribute";
9+
private const string CommandAttributeGenericFullName = $"{Content.CommonNamespaceName}.CommandAttribute<T>";
10+
private const string OptionAttributeFullName = $"{Content.CommonNamespaceName}.OptionAttribute";
1111

1212
public void Initialize(IncrementalGeneratorInitializationContext context)
1313
{

new-cli/GitVersion.Cli.Generator/Content.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ namespace GitVersion;
33
public static class Content
44
{
55
internal const string GeneratedNamespaceName = "GitVersion.Generated";
6-
internal const string InfraNamespaceName = "GitVersion";
7-
internal const string DependencyInjectionNamespaceName = "GitVersion.Infrastructure";
6+
internal const string CommonNamespaceName = "GitVersion";
7+
internal const string InfrastructureNamespaceName = "GitVersion.Infrastructure";
88
internal const string CommandNamespaceName = "GitVersion.Commands";
99

1010
/*language=cs*/
@@ -30,7 +30,7 @@ public static class Content
3030
{{- if Model.SettingsTypeNamespace != Model.CommandTypeNamespace }}
3131
using {{Model.SettingsTypeNamespace}};{{ end }}
3232
33-
namespace {{Namespace}};
33+
namespace {{GeneratedNamespaceName}};
3434
3535
public class {{Model.CommandTypeName}}Impl : Command, ICommandImpl
3636
{
@@ -83,8 +83,8 @@ Task<int> Run(ParseResult parseResult, CancellationToken cancellationToken)
8383
{{{GeneratedHeader}}}
8484
using System.CommandLine;
8585
86-
using {{InfraNamespaceName}};
87-
namespace {{Namespace}};
86+
using {{CommonNamespaceName}};
87+
namespace {{GeneratedNamespaceName}};
8888
8989
public class RootCommandImpl : RootCommand
9090
{
@@ -115,12 +115,12 @@ private void AddCommand(ICommandImpl command, IDictionary<string, ICommandImpl>
115115
public const string CommandsModuleContent = $$$"""
116116
{{{GeneratedHeader}}}
117117
using System.CommandLine;
118-
using {{DependencyInjectionNamespaceName}};
118+
using {{InfrastructureNamespaceName}};
119119
using {{CommandNamespaceName}};
120-
using {{InfraNamespaceName}};
120+
using {{CommonNamespaceName}};
121121
using Microsoft.Extensions.DependencyInjection;
122122
123-
namespace {{Namespace}};
123+
namespace {{GeneratedNamespaceName}};
124124
125125
public class CommandsModule : IGitVersionModule
126126
{

new-cli/GitVersion.Cli.Generator/SystemCommandlineGenerator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal override void GenerateSourceCode(SourceProductionContext context, Immut
1515
var commandHandlerSource = commandHandlerTemplate.Render(new
1616
{
1717
Model = commandInfo,
18-
Namespace = Content.GeneratedNamespaceName
18+
Content.GeneratedNamespaceName
1919
}, member => member.Name);
2020

2121
context.AddSource($"{commandInfo.CommandTypeName}Impl.g.cs", string.Join("\n", commandHandlerSource));
@@ -25,18 +25,18 @@ internal override void GenerateSourceCode(SourceProductionContext context, Immut
2525
var commandHandlersModuleSource = commandHandlersModuleTemplate.Render(new
2626
{
2727
Model = commandInfos,
28-
Namespace = Content.GeneratedNamespaceName,
29-
Content.InfraNamespaceName,
30-
Content.DependencyInjectionNamespaceName,
28+
Content.GeneratedNamespaceName,
29+
Content.CommonNamespaceName,
30+
Content.InfrastructureNamespaceName,
3131
Content.CommandNamespaceName
3232
}, member => member.Name);
3333
context.AddSource("CommandsModule.g.cs", string.Join("\n", commandHandlersModuleSource));
3434

3535
var rootCommandHandlerTemplate = Template.Parse(Content.RootCommandImplContent);
3636
var rootCommandHandlerSource = rootCommandHandlerTemplate.Render(new
3737
{
38-
Namespace = Content.GeneratedNamespaceName,
39-
Content.InfraNamespaceName
38+
Content.GeneratedNamespaceName,
39+
Content.CommonNamespaceName
4040
}, member => member.Name);
4141
context.AddSource("RootCommandImpl.g.cs", string.Join("\n", rootCommandHandlerSource));
4242
}
Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<ItemGroup>
3-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
4-
<PackageReference Include="Polly" />
5-
<PackageReference Include="System.IO.Abstractions" />
6-
</ItemGroup>
7-
<ItemGroup>
8-
<Compile Include="..\..\src\GitVersion.Core\Core\Abstractions\IEnvironment.cs" Link="Infrastructure\%(Filename)%(Extension)" />
9-
<Compile Include="..\..\src\GitVersion.Core\Core\Exceptions\WarningException.cs" Link="Exceptions\%(Filename)%(Extension)"/>
10-
<Compile Include="..\..\src\GitVersion.Core\Core\RegexPatterns.cs" Link="%(Filename)%(Extension)" />
11-
<Compile Include="..\..\src\GitVersion.Core\Extensions\DictionaryExtensions.cs" Link="%(Filename)%(Extension)" />
12-
<Compile Include="..\..\src\GitVersion.Core\Extensions\StringExtensions.cs" Link="Extensions\StringExtensions.cs" />
13-
<Compile Include="..\..\src\GitVersion.Core\Extensions\CommonExtensions.cs" Link="Extensions\CommonExtensions.cs" />
14-
<Compile Include="..\..\src\GitVersion.Core\Helpers\*.cs" Link="Helpers\%(Filename)%(Extension)" />
15-
<Compile Include="..\..\src\GitVersion.Core\Git\*.cs" Link="Git\%(Filename)%(Extension)" />
16-
<Compile Include="..\..\src\GitVersion.Core\SemVer\*.cs" Link="SemVer\%(Filename)%(Extension)"/>
17-
</ItemGroup>
18-
<ItemGroup>
19-
<InternalsVisibleTo Include="GitVersion.Core" />
20-
</ItemGroup>
2+
<ItemGroup>
3+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
4+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
5+
<PackageReference Include="Polly" />
6+
<PackageReference Include="System.IO.Abstractions" />
7+
</ItemGroup>
8+
<ItemGroup>
9+
<Compile Include="..\..\src\GitVersion.Core\Core\Abstractions\IEnvironment.cs" Link="Infrastructure\%(Filename)%(Extension)" />
10+
<Compile Include="..\..\src\GitVersion.Core\Core\Exceptions\WarningException.cs" Link="Exceptions\%(Filename)%(Extension)" />
11+
<Compile Include="..\..\src\GitVersion.Core\Core\RegexPatterns.cs" Link="%(Filename)%(Extension)" />
12+
<Compile Include="..\..\src\GitVersion.Core\Extensions\DictionaryExtensions.cs" Link="%(Filename)%(Extension)" />
13+
<Compile Include="..\..\src\GitVersion.Core\Extensions\StringExtensions.cs" Link="Extensions\StringExtensions.cs" />
14+
<Compile Include="..\..\src\GitVersion.Core\Extensions\CommonExtensions.cs" Link="Extensions\CommonExtensions.cs" />
15+
<Compile Include="..\..\src\GitVersion.Core\Helpers\*.cs" Link="Helpers\%(Filename)%(Extension)" />
16+
<Compile Include="..\..\src\GitVersion.Core\Git\*.cs" Link="Git\%(Filename)%(Extension)" />
17+
<Compile Include="..\..\src\GitVersion.Core\SemVer\*.cs" Link="SemVer\%(Filename)%(Extension)" />
18+
</ItemGroup>
19+
<ItemGroup>
20+
<InternalsVisibleTo Include="GitVersion.Core" />
21+
</ItemGroup>
2122
</Project>

new-cli/GitVersion.Common/Infrastructure/ILogger.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

new-cli/GitVersion.Configuration/ConfigCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using GitVersion.Extensions;
2-
using GitVersion.Infrastructure;
2+
using Microsoft.Extensions.Logging;
33

44
namespace GitVersion.Commands;
55

new-cli/GitVersion.Configuration/Init/ConfigInitCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using GitVersion.Extensions;
2-
using GitVersion.Infrastructure;
2+
using Microsoft.Extensions.Logging;
33

44
namespace GitVersion.Commands;
55

0 commit comments

Comments
 (0)