Skip to content

Commit d48ff8a

Browse files
Copilotarturcic
andcommitted
WIP: Migrate core files from ILog to ILogger - partial migration
Co-authored-by: arturcic <[email protected]>
1 parent 5ca988f commit d48ff8a

19 files changed

+156
-145
lines changed

src/GitVersion.Configuration/ConfigurationFileLocator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using System.IO.Abstractions;
22
using GitVersion.Extensions;
33
using GitVersion.Helpers;
4-
using GitVersion.Logging;
4+
using Microsoft.Extensions.Logging;
55
using Microsoft.Extensions.Options;
66

77
namespace GitVersion.Configuration;
88

99
internal class ConfigurationFileLocator(
1010
IFileSystem fileSystem,
11-
ILog log,
11+
ILogger<ConfigurationFileLocator> logger,
1212
IOptions<GitVersionOptions> options)
1313
: IConfigurationFileLocator
1414
{
@@ -26,7 +26,7 @@ internal class ConfigurationFileLocator(
2626
];
2727

2828
private readonly IFileSystem fileSystem = fileSystem.NotNull();
29-
private readonly ILog log = log.NotNull();
29+
private readonly ILogger<ConfigurationFileLocator> logger = log.NotNull();
3030
private readonly IOptions<GitVersionOptions> options = options.NotNull();
3131

3232
private string? ConfigurationFile => options.Value.ConfigurationInfo.ConfigurationFile;
@@ -43,7 +43,7 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
4343
var customConfigurationFile = GetCustomConfigurationFilePathIfEligable(directoryPath);
4444
if (!string.IsNullOrWhiteSpace(customConfigurationFile))
4545
{
46-
this.log.Info($"Found configuration file at '{customConfigurationFile}'");
46+
this.logger.LogInformation($"Found configuration file at '{customConfigurationFile}'");
4747
return customConfigurationFile;
4848
}
4949

@@ -55,10 +55,10 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
5555
var files = fileSystem.Directory.GetFiles(directoryPath);
5656
foreach (var fileName in this.SupportedConfigFileNames)
5757
{
58-
this.log.Debug($"Trying to find configuration file {fileName} at '{directoryPath}'");
58+
this.logger.LogDebug($"Trying to find configuration file {fileName} at '{directoryPath}'");
5959
var matchingFile = files.FirstOrDefault(file => string.Equals(FileSystemHelper.Path.GetFileName(file), fileName, StringComparison.OrdinalIgnoreCase));
6060
if (matchingFile == null) continue;
61-
this.log.Info($"Found configuration file at '{matchingFile}'");
61+
this.logger.LogInformation($"Found configuration file at '{matchingFile}'");
6262
return matchingFile;
6363
}
6464

src/GitVersion.Configuration/ConfigurationProvider.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.IO.Abstractions;
22
using GitVersion.Configuration.Workflows;
33
using GitVersion.Extensions;
4-
using GitVersion.Logging;
4+
using Microsoft.Extensions.Logging;
55
using Microsoft.Extensions.Options;
66
using YamlDotNet.Core;
77

@@ -10,14 +10,14 @@ namespace GitVersion.Configuration;
1010
internal class ConfigurationProvider(
1111
IConfigurationFileLocator configFileLocator,
1212
IFileSystem fileSystem,
13-
ILog log,
13+
ILogger<ConfigurationProvider> logger,
1414
IConfigurationSerializer configurationSerializer,
1515
IOptions<GitVersionOptions> options)
1616
: IConfigurationProvider
1717
{
1818
private readonly IConfigurationFileLocator configFileLocator = configFileLocator.NotNull();
1919
private readonly IFileSystem fileSystem = fileSystem.NotNull();
20-
private readonly ILog log = log.NotNull();
20+
private readonly ILogger<ConfigurationProvider> logger = log.NotNull();
2121
private readonly IConfigurationSerializer configurationSerializer = configurationSerializer.NotNull();
2222
private readonly IOptions<GitVersionOptions> options = options.NotNull();
2323

@@ -77,17 +77,17 @@ private IGitVersionConfiguration ProvideConfiguration(string? configFile,
7777
{
7878
if (configFilePath == null)
7979
{
80-
this.log.Info("No configuration file found, using default configuration");
80+
this.logger.LogInformation("No configuration file found, using default configuration");
8181
return null;
8282
}
8383

8484
if (!this.fileSystem.File.Exists(configFilePath))
8585
{
86-
this.log.Info($"Configuration file '{configFilePath}' not found");
86+
this.logger.LogInformation($"Configuration file '{configFilePath}' not found");
8787
return null;
8888
}
8989

90-
this.log.Info($"Using configuration file '{configFilePath}'");
90+
this.logger.LogInformation($"Using configuration file '{configFilePath}'");
9191
var content = fileSystem.File.ReadAllText(configFilePath);
9292
return configurationSerializer.Deserialize<Dictionary<object, object?>>(content);
9393
}

src/GitVersion.Core/Core/BranchesContainingCommitFinder.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using GitVersion.Common;
22
using GitVersion.Extensions;
33
using GitVersion.Git;
4+
using Microsoft.Extensions.Logging;
45
using GitVersion.Logging;
56

67
namespace GitVersion;
78

8-
internal class BranchesContainingCommitFinder(IRepositoryStore repositoryStore, ILog log)
9+
internal class BranchesContainingCommitFinder(IRepositoryStore repositoryStore, ILogger<BranchesContainingCommitFinder> logger)
910
{
10-
private readonly ILog log = log.NotNull();
11+
private readonly ILogger<BranchesContainingCommitFinder> logger = log.NotNull();
1112
private readonly IRepositoryStore repositoryStore = repositoryStore.NotNull();
1213

1314
public IEnumerable<IBranch> GetBranchesContainingCommit(ICommit commit, IEnumerable<IBranch>? branches = null, bool onlyTrackedBranches = false)
@@ -23,16 +24,16 @@ public IEnumerable<IBranch> GetBranchesContainingCommit(ICommit commit, IEnumera
2324

2425
private IEnumerable<IBranch> InnerGetBranchesContainingCommit(ICommit commit, IEnumerable<IBranch> branches, bool onlyTrackedBranches)
2526
{
26-
using (log.IndentLog($"Getting branches containing the commit '{commit.Id}'."))
27+
using (logger.IndentLog($"Getting branches containing the commit '{commit.Id}'."))
2728
{
2829
var directBranchHasBeenFound = false;
29-
log.Info("Trying to find direct branches.");
30+
logger.LogInformation("Trying to find direct branches.");
3031
// TODO: It looks wasteful looping through the branches twice. Can't these loops be merged somehow? @asbjornu
3132
var branchList = branches.ToList();
3233
foreach (var branch in branchList.Where(branch => BranchTipIsNullOrCommit(branch, commit) && !IncludeTrackedBranches(branch, onlyTrackedBranches)))
3334
{
3435
directBranchHasBeenFound = true;
35-
log.Info($"Direct branch found: '{branch}'.");
36+
logger.LogInformation($"Direct branch found: '{branch}'.");
3637
yield return branch;
3738
}
3839

@@ -41,20 +42,20 @@ private IEnumerable<IBranch> InnerGetBranchesContainingCommit(ICommit commit, IE
4142
yield break;
4243
}
4344

44-
log.Info($"No direct branches found, searching through {(onlyTrackedBranches ? "tracked" : "all")} branches.");
45+
logger.LogInformation($"No direct branches found, searching through {(onlyTrackedBranches ? "tracked" : "all")} branches.");
4546
foreach (var branch in branchList.Where(b => IncludeTrackedBranches(b, onlyTrackedBranches)))
4647
{
47-
log.Info($"Searching for commits reachable from '{branch}'.");
48+
logger.LogInformation($"Searching for commits reachable from '{branch}'.");
4849

4950
var commits = this.repositoryStore.GetCommitsReacheableFrom(commit, branch);
5051

5152
if (!commits.Any())
5253
{
53-
log.Info($"The branch '{branch}' has no matching commits.");
54+
logger.LogInformation($"The branch '{branch}' has no matching commits.");
5455
continue;
5556
}
5657

57-
log.Info($"The branch '{branch}' has a matching commit.");
58+
logger.LogInformation($"The branch '{branch}' has a matching commit.");
5859
yield return branch;
5960
}
6061
}

0 commit comments

Comments
 (0)