Skip to content

Commit

Permalink
rearrange code in TestLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Dec 23, 2024
1 parent 55146e1 commit 6fdc8e7
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/TestInfrastructure/Framework/TestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class TestLogger : ILogger, ILogWriter, ILogVerbosityIndicator
public event EventHandler LogMessageAdded;

private readonly bool logToConsole;
private readonly bool logThreadId;
private readonly ILogger logger;

public TestLogger(bool logToConsole = false, bool logThreadId = false)
Expand All @@ -40,7 +41,7 @@ public TestLogger(bool logToConsole = false, bool logThreadId = false)
// link to show the output.
this.logToConsole = logToConsole;

IsThreadIdEnabled = logThreadId;
this.logThreadId = logThreadId;
logger = LoggerFactory.Default.Create(this, this);
}

Expand Down Expand Up @@ -95,18 +96,6 @@ public void Reset()
OutputStrings = new BlockingCollection<string>();
}

void ILogWriter.WriteLine(string message)
{
var messageToLog = message + Environment.NewLine;
OutputStrings.Add(messageToLog);
if (logToConsole)
{
Console.WriteLine(messageToLog);
}

LogMessageAdded?.Invoke(this, EventArgs.Empty);
}

#region ILogger methods

public void WriteLine(string message) => logger.WriteLine(message);
Expand All @@ -121,7 +110,18 @@ void ILogWriter.WriteLine(string message)

#endregion

public bool IsVerboseEnabled => true;
public bool IsThreadIdEnabled { get; }
void ILogWriter.WriteLine(string message)
{
var messageToLog = message + Environment.NewLine;
OutputStrings.Add(messageToLog);
if (logToConsole)
{
Console.WriteLine(messageToLog);
}

LogMessageAdded?.Invoke(this, EventArgs.Empty);
}
bool ILogVerbosityIndicator.IsVerboseEnabled => true;
bool ILogVerbosityIndicator.IsThreadIdEnabled => logThreadId;
}
}

0 comments on commit 6fdc8e7

Please sign in to comment.