forked from sarbian/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamLogger.cs
More file actions
32 lines (26 loc) · 856 Bytes
/
Copy pathStreamLogger.cs
File metadata and controls
32 lines (26 loc) · 856 Bytes
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;
using System.IO;
namespace ModuleManager.Logging
{
public sealed class StreamLogger : IBasicLogger, IDisposable
{
private readonly StreamWriter streamWriter;
private bool disposed = false;
public StreamLogger(Stream stream)
{
streamWriter = new StreamWriter(stream);
}
public void Log(ILogMessage message)
{
if (disposed) throw new InvalidOperationException("Object has already been disposed");
if (message == null) throw new ArgumentNullException(nameof(message));
streamWriter.WriteLine(message.ToLogString());
}
public void Dispose()
{
// Flushes and closes the StreamWriter and the underlying stream
streamWriter.Close();
disposed = true;
}
}
}