123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using JetBrains.Annotations;
- using UnityEngine;
- namespace Logging
- {
- public class AsyncLogFileWriter
- {
- private readonly StreamWriter writer;
- public AsyncLogFileWriter(string path)
- {
- var fileInfo = new FileInfo(path);
- if (!fileInfo.Directory?.Exists ?? false)
- {
- fileInfo.Directory?.Create();
- }
- writer = new StreamWriter(path) {AutoFlush = true};
- }
- [Obsolete("Use WriteDataLine(values)")] //TODO
- public async Task WriteDataLine<T>(T xValue, IEnumerable<T> values)
- {
- await writer.WriteLineAsync($"{xValue}\t{string.Join("\t", values)}");
- }
-
- public async Task WriteDataLine<T>(IEnumerable<T> values)
- {
- await writer.WriteLineAsync($"{string.Join("\t", values)}");
- }
- public async Task WriteDataLines<T>(IEnumerable<IEnumerable<T>> lines)
- {
- var sb = new StringBuilder();
- foreach (var l in lines)
- {
- sb.Append($"{string.Join("\t", l)}\n");
- }
- await writer.WriteAsync(sb.ToString());
- }
- public void Dispose()
- {
- writer?.Close();
- }
-
- }
- }
|