better crash logging

pull/702/head
Luke Pulverenti 11 years ago
parent 645a41b193
commit 3d3876c9a9

@ -471,7 +471,10 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
foreach (var pair in options.RequestHeaders.ToList()) foreach (var pair in options.RequestHeaders.ToList())
{ {
message.Headers.Add(pair.Key, pair.Value); if (!message.Headers.TryAddWithoutValidation(pair.Key, pair.Value))
{
_logger.Error("Unable to add request header {0} with value {1}", pair.Key, pair.Value);
}
} }
return message; return message;
@ -484,9 +487,31 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
/// <returns>System.Nullable{System.Int64}.</returns> /// <returns>System.Nullable{System.Int64}.</returns>
private long? GetContentLength(HttpResponseMessage response) private long? GetContentLength(HttpResponseMessage response)
{ {
IEnumerable<string> lengthValues; IEnumerable<string> lengthValues = null;
// Seeing some InvalidOperationException here under mono
try
{
response.Headers.TryGetValues("content-length", out lengthValues);
}
catch (InvalidOperationException ex)
{
_logger.ErrorException("Error accessing response.Headers.TryGetValues Content-Length", ex);
}
if (lengthValues == null)
{
try
{
response.Content.Headers.TryGetValues("content-length", out lengthValues);
}
catch (InvalidOperationException ex)
{
_logger.ErrorException("Error accessing response.Content.Headers.TryGetValues Content-Length", ex);
}
}
if (!response.Headers.TryGetValues("content-length", out lengthValues) && !response.Content.Headers.TryGetValues("content-length", out lengthValues)) if (lengthValues == null)
{ {
return null; return null;
} }

@ -1,23 +1,25 @@
<Properties> <Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" /> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Server.Mono\FFMpeg\FFMpegDownloadInfo.cs"> <MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Model\Web\QueryStringDictionary.cs">
<Files> <Files>
<File FileName="MediaBrowser.Server.Implementations\HttpServer\HttpServer.cs" Line="1" Column="1" /> <File FileName="MediaBrowser.Server.Implementations\HttpServer\HttpServer.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Networking\NetworkManager.cs" Line="1" Column="1" /> <File FileName="MediaBrowser.Server.Mono\Networking\NetworkManager.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="1" Column="1" /> <File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="1" Column="1" /> <File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="1" Column="1" /> <File FileName="MediaBrowser.Server.Mono\Program.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.ServerApplication\FFMpeg\FFMpegDownloader.cs" Line="1" Column="1" /> <File FileName="MediaBrowser.ServerApplication\FFMpeg\FFMpegDownloader.cs" Line="31" Column="30" />
<File FileName="MediaBrowser.Server.Mono\FFMpeg\FFMpegDownloadInfo.cs" Line="21" Column="1" /> <File FileName="MediaBrowser.Server.Mono\FFMpeg\FFMpegDownloadInfo.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Model\Web\QueryStringDictionary.cs" Line="26" Column="10" />
</Files> </Files>
<Pads> <Pads>
<Pad Id="ProjectPad"> <Pad Id="ProjectPad">
<State expanded="True"> <State expanded="True">
<Node name="MediaBrowser.Model" expanded="True" /> <Node name="MediaBrowser.Model" expanded="True">
<Node name="References" expanded="True" selected="True" />
<Node name="Web" expanded="True" />
</Node>
<Node name="MediaBrowser.Server.Mono" expanded="True"> <Node name="MediaBrowser.Server.Mono" expanded="True">
<Node name="FFMpeg" expanded="True"> <Node name="FFMpeg" expanded="True" />
<Node name="FFMpegDownloadInfo.cs" selected="True" />
</Node>
</Node> </Node>
</State> </State>
</Pad> </Pad>

@ -259,7 +259,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="sqlite3.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="swagger-ui\css\hightlight.default.css"> <Content Include="swagger-ui\css\hightlight.default.css">

@ -135,5 +135,8 @@
<None Include="tray.png"> <None Include="tray.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="sqlite3.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -206,7 +206,7 @@ namespace MediaBrowser.Server.Mono
{ {
var exception = (Exception)e.ExceptionObject; var exception = (Exception)e.ExceptionObject;
_logger.ErrorException("UnhandledException", exception); LogUnhandledException(exception);
if (!Debugger.IsAttached) if (!Debugger.IsAttached)
{ {
@ -214,6 +214,19 @@ namespace MediaBrowser.Server.Mono
} }
} }
private static void LogUnhandledException(Exception ex)
{
_logger.ErrorException("UnhandledException", ex);
_appHost.LogManager.Flush ();
var path = Path.Combine(_appHost.ServerConfigurationManager.ApplicationPaths.LogDirectoryPath, "crash_" + Guid.NewGuid() + ".txt");
var builder = LogHelper.GetLogMessage(ex);
File.WriteAllText(path, builder.ToString());
}
/// <summary> /// <summary>
/// Performs the update if needed. /// Performs the update if needed.
/// </summary> /// </summary>

@ -398,7 +398,7 @@ namespace MediaBrowser.ServerApplication
{ {
var exception = (Exception)e.ExceptionObject; var exception = (Exception)e.ExceptionObject;
_logger.ErrorException("UnhandledException", exception); LogUnhandledException(exception);
_appHost.LogManager.Flush(); _appHost.LogManager.Flush();
@ -413,6 +413,17 @@ namespace MediaBrowser.ServerApplication
} }
} }
private static void LogUnhandledException(Exception ex)
{
_logger.ErrorException("UnhandledException", ex);
var path = Path.Combine(_appHost.ServerConfigurationManager.ApplicationPaths.LogDirectoryPath, "crash_" + Guid.NewGuid() + ".txt");
var builder = LogHelper.GetLogMessage(ex);
File.WriteAllText(path, builder.ToString());
}
/// <summary> /// <summary>
/// Performs the update if needed. /// Performs the update if needed.
/// </summary> /// </summary>

Loading…
Cancel
Save