protected override async Task WriteBatch(System.Collections.Generic.List<LogBatchEntry> batchEntries)
{
try
{
var filePath = FilePath;
var directoryName = Path.GetDirectoryName(filePath);
if (!string.IsNullOrWhiteSpace(directoryName))
{
Directory.CreateDirectory(directoryName);
}
var fileInfo = new FileInfo(filePath);
if (fileInfo.Exists && (fileInfo.Length / 1024 >= MaxSizeInKiloBytes))
{
CreateCopyOfCurrentLogFile(FilePath);
}
using (var fileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.Read))
{
using (var writer = new StreamWriter(fileStream))
{
foreach (var batchEntry in batchEntries)
{
var message = FormatLogEvent(batchEntry.Log, batchEntry.Message, batchEntry.LogEvent, batchEntry.ExtraData, batchEntry.Time);
writer.WriteLine(message);
}
writer.Flush();
}
}
}
catch (Exception)
{
// Swallow
}
}