123456789101112131415161718192021222324252627282930313233343536373839 |
- using System;
- using Newtonsoft.Json;
- using SongVocalSectionAnalyser.Common.Logging;
- using SongVocalSectionAnalyser.Common.Logging.JsonConverters;
- using SongVocalSectionAnalyser.Common.Logging.Model;
- using Xunit.Abstractions;
- namespace SongVocalSectionAnalyser.Tests
- {
- internal class XunitTestLogger : LoggerBase
- {
- private readonly ITestOutputHelper _output;
- public XunitTestLogger(ITestOutputHelper output)
- {
- _output = output;
- }
- protected override void WriteLog(LogEntry entry)
- {
- string dj;
- try
- {
- dj = entry.Details == null ? "" : JsonConvert.SerializeObject(entry.Details, LogJsonSerializerSettings.Default);
- }
- catch (Exception e)
- {
- var hold = entry.MakeCopyWithoutDetails();
- hold.Details = new { SerializationFail = e.Message, DowngradeToString = entry.Details?.ToString() };
- dj = JsonConvert.SerializeObject(hold, LogJsonSerializerSettings.Default);
- }
- _output.WriteLine($"{entry.Time}|{entry.Level}|{entry.Thread.Id}:{entry.Thread.Name}|{entry.Summary}|{dj}");
- }
- }
- }
|