Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 5cf4e7b

Browse files
Fixed some logging issues
1 parent c147d39 commit 5cf4e7b

File tree

5 files changed

+16
-55
lines changed

5 files changed

+16
-55
lines changed

src/GitTools.Core/Extensions/LibGitExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static void CheckoutFilesIfExist(this IRepository repository, params stri
6060
{
6161
try
6262
{
63-
Log.Info(" Trying to check out '{0}'", fileName);
63+
Log.InfoFormat(" Trying to check out '{0}'", fileName);
6464

6565
var headBranch = repository.Head;
6666
var tip = headBranch.Tip;
@@ -82,7 +82,7 @@ public static void CheckoutFilesIfExist(this IRepository repository, params stri
8282
}
8383
catch (Exception ex)
8484
{
85-
Log.Warning(" An error occurred while checking out '{0}': '{1}'", fileName, ex.Message);
85+
Log.WarnFormat(" An error occurred while checking out '{0}': '{1}'", fileName, ex.Message);
8686
}
8787
}
8888
}

src/GitTools.Core/Git/GitPreparer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ private string GetGitInfoFromUrl(IRepositoryContext context, string gitDirectory
3535
gitDirectory = Path.Combine(gitDirectory, ".git");
3636
if (Directory.Exists(gitDirectory))
3737
{
38-
Log.Info("Deleting existing .git folder from '{0}' to force new checkout from url", gitDirectory);
38+
Log.InfoFormat("Deleting existing .git folder from '{0}' to force new checkout from url", gitDirectory);
3939

4040
DeleteHelper.DeleteGitRepository(gitDirectory);
4141
}
4242

43-
Log.Info("Retrieving git info from url '{0}'", context.Url);
43+
Log.InfoFormat("Retrieving git info from url '{0}'", context.Url);
4444

4545
Credentials credentials = null;
4646
if (!string.IsNullOrWhiteSpace(context.Username) && !string.IsNullOrWhiteSpace(context.Password))
4747
{
48-
Log.Info("Setting up credentials using name '{0}'", context.Username);
48+
Log.InfoFormat("Setting up credentials using name '{0}'", context.Username);
4949

5050
credentials = new UsernamePasswordCredentials
5151
{
@@ -91,7 +91,7 @@ private string GetGitInfoFromUrl(IRepositoryContext context, string gitDirectory
9191

9292
if (newHead != null)
9393
{
94-
Log.Info("Switching to branch '{0}'", context.Branch);
94+
Log.InfoFormat("Switching to branch '{0}'", context.Branch);
9595

9696
repository.Refs.UpdateTarget(repository.Refs.Head, newHead);
9797
}

src/GitTools.Core/Helpers/GitHelper.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static void NormalizeGitDirectory(string gitDirectory)
1414
{
1515
var remote = EnsureOnlyOneRemoteIsDefined(repo);
1616

17-
Log.Info("Fetching from remote '{0}' using the following refspecs: {1}.",
17+
Log.InfoFormat("Fetching from remote '{0}' using the following refspecs: {1}.",
1818
remote.Name, string.Join(", ", remote.FetchRefSpecs.Select(r => r.Specification)));
1919

2020
var fetchOptions = new FetchOptions();
@@ -24,11 +24,11 @@ public static void NormalizeGitDirectory(string gitDirectory)
2424

2525
if (!repo.Info.IsHeadDetached)
2626
{
27-
Log.Info("HEAD points at branch '{0}'.", repo.Refs.Head.TargetIdentifier);
27+
Log.InfoFormat("HEAD points at branch '{0}'.", repo.Refs.Head.TargetIdentifier);
2828
return;
2929
}
3030

31-
Log.Info("HEAD is detached and points at commit '{0}'.", repo.Refs.Head.TargetIdentifier);
31+
Log.InfoFormat("HEAD is detached and points at commit '{0}'.", repo.Refs.Head.TargetIdentifier);
3232

3333
CreateFakeBranchPointingAtThePullRequestTip(repo);
3434
}
@@ -55,7 +55,7 @@ private static void CreateFakeBranchPointingAtThePullRequestTip(Repository repo)
5555
}
5656

5757
var canonicalName = refs[0].CanonicalName;
58-
Log.Info("Found remote tip '{0}' pointing at the commit '{1}'.", canonicalName, headTipSha);
58+
Log.InfoFormat("Found remote tip '{0}' pointing at the commit '{1}'.", canonicalName, headTipSha);
5959

6060
if (!canonicalName.StartsWith("refs/pull/"))
6161
{
@@ -64,10 +64,10 @@ private static void CreateFakeBranchPointingAtThePullRequestTip(Repository repo)
6464

6565
var fakeBranchName = canonicalName.Replace("refs/pull/", "refs/heads/pull/");
6666

67-
Log.Info("Creating fake local branch '{0}'.", fakeBranchName);
67+
Log.InfoFormat("Creating fake local branch '{0}'.", fakeBranchName);
6868
repo.Refs.Add(fakeBranchName, new ObjectId(headTipSha));
6969

70-
Log.Info("Checking local branch '{0}' out.", fakeBranchName);
70+
Log.InfoFormat("Checking local branch '{0}' out.", fakeBranchName);
7171
repo.Checkout(fakeBranchName);
7272
}
7373

@@ -80,11 +80,11 @@ private static void CreateMissingLocalBranchesFromRemoteTrackingOnes(IRepository
8080
var localCanonicalName = "refs/heads/" + remoteTrackingReference.CanonicalName.Substring(prefix.Length);
8181
if (repo.Refs.Any(x => x.CanonicalName == localCanonicalName))
8282
{
83-
Log.Info("Skipping local branch creation since it already exists '{0}'.", remoteTrackingReference.CanonicalName);
83+
Log.InfoFormat("Skipping local branch creation since it already exists '{0}'.", remoteTrackingReference.CanonicalName);
8484
continue;
8585
}
8686

87-
Log.Info("Creating local branch from remote tracking '{0}'.", remoteTrackingReference.CanonicalName);
87+
Log.InfoFormat("Creating local branch from remote tracking '{0}'.", remoteTrackingReference.CanonicalName);
8888

8989
var symbolicReference = remoteTrackingReference as SymbolicReference;
9090
if (symbolicReference == null)
@@ -106,7 +106,7 @@ private static Remote EnsureOnlyOneRemoteIsDefined(IRepository repo)
106106
if (howMany == 1)
107107
{
108108
var remote = remotes.Single();
109-
Log.Info("One remote found ({0} -> '{1}').", remote.Name, remote.Url);
109+
Log.InfoFormat("One remote found ({0} -> '{1}').", remote.Name, remote.Url);
110110
return remote;
111111
}
112112

src/GitTools.Core/IO/TemporaryFilesContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public TemporaryFilesContext()
2222
/// </summary>
2323
public void Dispose()
2424
{
25-
Log.Info("Deleting temporary files from '{0}'", _rootDirectory);
25+
Log.InfoFormat("Deleting temporary files from '{0}'", _rootDirectory);
2626

2727
try
2828
{

src/GitTools.Core/Logging/Extensions/LogExtensions.cs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,6 @@
66

77
internal static class LogExtensions
88
{
9-
public static void Debug(this ILog log, string messageFormat, params object[] args)
10-
{
11-
var message = FormatMessage(messageFormat, args);
12-
13-
log.Debug(message);
14-
}
15-
16-
public static void Info(this ILog log, string messageFormat, params object[] args)
17-
{
18-
var message = FormatMessage(messageFormat, args);
19-
20-
log.Info(message);
21-
}
22-
23-
public static void Warning(this ILog log, string messageFormat, params object[] args)
24-
{
25-
var message = FormatMessage(messageFormat, args);
26-
27-
log.Warning(message);
28-
}
29-
30-
public static void Error(this ILog log, string messageFormat, params object[] args)
31-
{
32-
var message = FormatMessage(messageFormat, args);
33-
34-
log.Error(message);
35-
}
36-
37-
private static string FormatMessage(string messageFormat, params object[] args)
38-
{
39-
var message = messageFormat ?? string.Empty;
40-
if (args != null && args.Length > 0)
41-
{
42-
message = string.Format(message, args);
43-
}
44-
45-
return message;
46-
}
47-
489
/// <summary>
4910
/// Writes the specified message as error message and then throws the specified exception.
5011
/// <para/>

0 commit comments

Comments
 (0)