/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Test/Perf/Utilities/Logger.cs
68 строк
2 KB
Jared Parsons
generated move
28 сен 2020, 19:36
28 сен 2020, 19:36
1cca63b
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #nullable disable using System; using System.IO; using System.Text; namespace Roslyn.Test.Performance.Utilities { /// <summary> /// An interface for logging messages. A global ILogger implementation /// exists at Roslyn.Test.Performance.Utilities.RuntimeSettings.logger. /// </summary> public interface ILogger { /// <summary> /// Logs a string through the logger. /// </summary> /// <param name="v"></param> void Log(string v); /// <summary> /// Flushes the cache (if one exists). /// </summary> void Flush(); } /// <summary> /// An implementation of ILogger that prints to the console, and also /// writes to a file. /// </summary> public class ConsoleAndFileLogger : ILogger { private readonly string _file; private readonly StringBuilder _buffer = new StringBuilder(); /// <summary> /// Constructs a new ConsoleAndFileLogger with a default log /// file of 'log.txt'. /// </summary> public ConsoleAndFileLogger() { if (Directory.Exists(TestUtilities.GetCPCDirectoryPath())) { _file = Path.Combine(TestUtilities.GetCPCDirectoryPath(), "perf-log.txt"); } else { _file = "./perf-log.txt"; } } void ILogger.Flush() { File.AppendAllText(_file, _buffer.ToString()); _buffer.Clear(); } void ILogger.Log(string v) { Console.WriteLine(DateTime.Now + " : " + v); _buffer.AppendLine(DateTime.Now + " : " + v); } } }