Repository navigation
Expand file tree
/
Copy pathStringLogger.cs
More file actions
72 lines (63 loc) · 1.97 KB
/
Copy pathStringLogger.cs
File metadata and controls
72 lines (63 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Text;
namespace SimpleGitVersion;
/// <summary>
/// Logger implementation in a string.
/// </summary>
public sealed class StringLogger : ILogger
{
readonly StringBuilder _b;
public StringLogger()
{
_b = new StringBuilder( 4096 );
_b.Append( "SimpleGitVersion:" ).AppendLine();
}
/// <summary>
/// Gets the inner builder.
/// </summary>
public StringBuilder Builder => _b;
void Append( string header, string prefix, string msg )
{
_b.Append( header );
var lines = msg.AsSpan().EnumerateLines();
if( lines.MoveNext() )
{
_b.Append( lines.Current ).AppendLine();
while( lines.MoveNext() )
{
_b.Append( prefix ).Append( lines.Current ).AppendLine();
}
}
else
{
_b.AppendLine();
}
}
/// <summary>
/// Appends the lines in a "| [Error] " block.
/// </summary>
/// <param name="msg">The error.</param>
public void Error( string msg ) => Append( "| [Error] ", "| ", msg );
/// <summary>
/// Appends the lines with "| " prefix.
/// </summary>
/// <param name="msg">The error.</param>
public void Info( string msg ) => Append( "| ", "| ", msg );
/// <summary>
/// Appends the lines in a "| [Warn] " block.
/// </summary>
/// <param name="msg">The error.</param>
public void Warn( string msg ) => Append( "| [Warn] ", "| ", msg );
/// <summary>
/// Should be called at the end of the operation. Adds the final version and build configuration.
/// </summary>
/// <param name="final"></param>
/// <returns></returns>
public string Conclude( ICommitBuildInfo final )
{
return _b.Append( "|=> " )
.Append( final.Version )
.Append( " (Configuration: " ).Append( final.BuildConfiguration )
.Append( ')' ).AppendLine().ToString();
}
}