better streaming logging

This commit is contained in:
LukePulverenti 2013-03-11 00:04:08 -04:00
parent de755c4b93
commit 7c677e0ee6
4 changed files with 39 additions and 13 deletions

View File

@ -135,11 +135,7 @@ namespace MediaBrowser.Api.Playback.Progressive
ApiEntryPoint.Instance.OnTranscodeBeginRequest(outputPath, TranscodingJobType.Progressive);
}
return new ProgressiveStreamWriter
{
Path = outputPath,
State = state
};
return new ProgressiveStreamWriter(outputPath, state, Logger);
}
/// <summary>

View File

@ -9,9 +9,22 @@ namespace MediaBrowser.Api.Playback.Progressive
{
public class ProgressiveStreamWriter : IStreamWriter
{
public string Path { get; set; }
public StreamState State { get; set; }
public ILogger Logger { get; set; }
private string Path { get; set; }
private StreamState State { get; set; }
private ILogger Logger { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ProgressiveStreamWriter" /> class.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="state">The state.</param>
/// <param name="logger">The logger.</param>
public ProgressiveStreamWriter(string path, StreamState state, ILogger logger)
{
Path = path;
State = state;
Logger = logger;
}
/// <summary>
/// Writes to.
@ -38,6 +51,8 @@ namespace MediaBrowser.Api.Playback.Progressive
catch (Exception ex)
{
Logger.ErrorException("Error streaming media", ex);
throw;
}
finally
{

View File

@ -267,7 +267,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
}
httpListenerResponse.ContentLength64 = stream.Length;
return new StreamWriter(stream);
return new StreamWriter(stream, Logger);
}
string content;

View File

@ -1,4 +1,6 @@
using ServiceStack.Service;
using MediaBrowser.Model.Logging;
using ServiceStack.Service;
using System;
using System.IO;
using System.Threading.Tasks;
@ -9,6 +11,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// </summary>
public class StreamWriter : IStreamWriter
{
private ILogger Logger { get; set; }
/// <summary>
/// Gets or sets the source stream.
/// </summary>
@ -19,9 +23,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// Initializes a new instance of the <see cref="StreamWriter" /> class.
/// </summary>
/// <param name="source">The source.</param>
public StreamWriter(Stream source)
/// <param name="logger">The logger.</param>
public StreamWriter(Stream source, ILogger logger)
{
SourceStream = source;
Logger = logger;
}
/// <summary>
@ -42,9 +48,18 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// <returns>Task.</returns>
private async Task WriteToAsync(Stream responseStream)
{
using (var src = SourceStream)
try
{
await src.CopyToAsync(responseStream).ConfigureAwait(false);
using (var src = SourceStream)
{
await src.CopyToAsync(responseStream).ConfigureAwait(false);
}
}
catch (Exception ex)
{
Logger.ErrorException("Error streaming media", ex);
throw;
}
}
}