/
ExporterBase.cs
32 lines (27 loc) · 1.01 KB
/
ExporterBase.cs
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
using System.Collections.Generic;
using System.IO;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Reports;
namespace BenchmarkDotNet.Exporters
{
public abstract class ExporterBase : IExporter
{
protected virtual string FileExtension => "txt";
protected virtual string FileNameSuffix => string.Empty;
protected virtual string FileCaption => "report";
public abstract void ExportToLog(Summary summary, ILogger logger);
public IEnumerable<string> ExportToFiles(Summary summary, ILogger consoleLogger)
{
var filePath = $"{Path.Combine(summary.ResultsDirectoryPath, summary.Title)}-{FileCaption}{FileNameSuffix}.{FileExtension}";
if (File.Exists(filePath))
{
File.Delete(filePath);
}
using (var stream = Portability.StreamWriter.FromPath(filePath))
{
ExportToLog(summary, new StreamLogger(stream));
}
return new [] { filePath };
}
}
}