2012-07-30 13:44:28 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2012-07-31 03:38:00 +00:00
|
|
|
|
namespace MediaBrowser.Common.Logging
|
2012-07-30 13:44:28 +00:00
|
|
|
|
{
|
2012-07-30 19:03:07 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides a Logger that can write to any Stream
|
|
|
|
|
/// </summary>
|
2012-09-10 19:11:40 +00:00
|
|
|
|
public class StreamLogger : ThreadedLogger
|
2012-07-30 13:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
private Stream Stream { get; set; }
|
|
|
|
|
|
|
|
|
|
public StreamLogger(Stream stream)
|
|
|
|
|
: base()
|
|
|
|
|
{
|
|
|
|
|
Stream = stream;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 19:11:40 +00:00
|
|
|
|
protected override void AsyncLogMessage(LogRow row)
|
2012-07-30 13:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
byte[] bytes = new UTF8Encoding().GetBytes(row.ToString() + Environment.NewLine);
|
|
|
|
|
Stream.Write(bytes, 0, bytes.Length);
|
|
|
|
|
Stream.Flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Dispose()
|
|
|
|
|
{
|
|
|
|
|
base.Dispose();
|
|
|
|
|
Stream.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|