Skip to content

Commit f3278ec

Browse files
eric-winklerarturcic
authored andcommitted
Don't try to format non-format strings.
Many consumers are doing a log.Info("somestring") and have no desire to trigger formatstring behavior. This change allows them to use '{' or '}' without running into formatting exceptions.
1 parent a4cb74b commit f3278ec

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using GitVersion.Logging;
2+
using NUnit.Framework;
3+
4+
namespace GitVersionCore.Tests.Logging
5+
{
6+
[TestFixture]
7+
public class LoggingTests
8+
{
9+
[Test]
10+
public void CanLogNonFormatStrings()
11+
{
12+
var log = new Log();
13+
14+
log.Info("Logging using git revision syntax eg. 1.0.0.0^{} shouldn't throw");
15+
}
16+
}
17+
}

src/GitVersionCore/Logging/Log.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public sealed class Log : ILog
1616

1717
public Log(): this(Array.Empty<ILogAppender>())
1818
{
19-
2019
}
2120

2221
public Log(params ILogAppender[] appenders)
@@ -35,7 +34,8 @@ public void Write(Verbosity verbosity, LogLevel level, string format, params obj
3534
return;
3635
}
3736

38-
var formattedString = FormatMessage(string.Format(format, args), level.ToString().ToUpperInvariant());
37+
var message = args.Any() ? string.Format(format, args) : format;
38+
var formattedString = FormatMessage(message, level.ToString().ToUpperInvariant());
3939
foreach (var appender in appenders)
4040
{
4141
appender.WriteTo(level, formattedString);

0 commit comments

Comments
 (0)