using System;
using System.IO;
namespace StardewModdingAPI.Framework
{
/// Manages reading and writing to log file.
internal class LogFileManager : IDisposable
{
/*********
** Properties
*********/
/// The underlying stream writer.
private readonly StreamWriter Stream;
/*********
** Public methods
*********/
/// Construct an instance.
/// The log file to write.
public LogFileManager(string path)
{
// create log directory if needed
string logDir = Path.GetDirectoryName(path);
if (logDir == null)
throw new ArgumentException($"The log path '{path}' is not valid.");
Directory.CreateDirectory(logDir);
// open log file stream
this.Stream = new StreamWriter(path, append: false) { AutoFlush = true };
}
/// Write a message to the log.
/// The message to log.
public void WriteLine(string message)
{
this.Stream.WriteLine(message);
}
/// Release all resources.
public void Dispose()
{
this.Stream.Dispose();
}
}
}