@@ -9,7 +9,8 @@ internal sealed class Log(params ILogAppender[] appenders) : ILog
9
9
private IEnumerable < ILogAppender > appenders = appenders ;
10
10
private readonly Regex obscurePasswordRegex = new ( "(https?://)(.+)(:.+@)" , RegexOptions . Compiled ) ;
11
11
private readonly StringBuilder sb = new ( ) ;
12
- private string indent = string . Empty ;
12
+ private string currentIndentation = string . Empty ;
13
+ private const string Indentation = " " ;
13
14
14
15
public Log ( ) : this ( [ ] )
15
16
{
@@ -36,27 +37,30 @@ public void Write(Verbosity verbosity, LogLevel level, string format, params obj
36
37
37
38
public IDisposable IndentLog ( string operationDescription )
38
39
{
39
- var start = DateTime . Now ;
40
+ var start = TimeProvider . System . GetTimestamp ( ) ;
40
41
Write ( Verbosity . Normal , LogLevel . Info , $ "-< Begin: { operationDescription } >-") ;
41
- this . indent += " " ;
42
+ this . currentIndentation += Indentation ;
42
43
43
44
return Disposable . Create ( ( ) =>
44
45
{
45
- var length = this . indent . Length - 2 ;
46
- this . indent = length > 0 ? this . indent [ ..length ] : "" ;
47
- Write ( Verbosity . Normal , LogLevel . Info , string . Format ( CultureInfo . InvariantCulture , "-< End: {0} (Took: {1:N}ms) >-" , operationDescription , DateTime . Now . Subtract ( start ) . TotalMilliseconds ) ) ;
46
+ var length = this . currentIndentation . Length - Indentation . Length ;
47
+ this . currentIndentation = length > 0 ? this . currentIndentation [ ..length ] : "" ;
48
+ var end = TimeProvider . System . GetTimestamp ( ) ;
49
+ var duration = TimeProvider . System . GetElapsedTime ( start , end ) . TotalMilliseconds ;
50
+ Write ( Verbosity . Normal , LogLevel . Info , string . Format ( CultureInfo . InvariantCulture , "-< End: {0} (Took: {1:N}ms) >-" , operationDescription , duration ) ) ;
48
51
} ) ;
49
52
}
50
53
51
54
public void Separator ( ) => Write ( Verbosity . Normal , LogLevel . Info , "-------------------------------------------------------" ) ;
52
55
53
- public void AddLogAppender ( ILogAppender logAppender ) => this . appenders = this . appenders . Concat ( new [ ] { logAppender } ) ;
56
+ public void AddLogAppender ( ILogAppender logAppender ) => this . appenders = this . appenders . Concat ( [ logAppender ] ) ;
54
57
55
58
public override string ToString ( ) => this . sb . ToString ( ) ;
56
59
57
60
private string FormatMessage ( string message , string level )
58
61
{
59
62
var obscuredMessage = this . obscurePasswordRegex . Replace ( message , "$1$2:*******@" ) ;
60
- return string . Format ( CultureInfo . InvariantCulture , "{0}{1} [{2:MM/dd/yy H:mm:ss:ff}] {3}" , this . indent , level , DateTime . Now , obscuredMessage ) ;
63
+ var timestamp = $ "{ DateTime . Now : yy-MM-dd H:mm:ss:ff} ";
64
+ return string . Format ( CultureInfo . InvariantCulture , "{0}{1} [{2}] {3}" , this . currentIndentation , level , timestamp , obscuredMessage ) ;
61
65
}
62
66
}
0 commit comments