added file logging to services.

This commit is contained in:
kay.one 2012-02-05 08:53:08 -08:00
parent ad9a7fa6e4
commit 1d1c62d376
12 changed files with 100 additions and 28 deletions

View File

@ -28,7 +28,7 @@ namespace NzbDrone.Common.Test
const string badTitle = "Bad Title";
ReportingService.ReportParseError(badTitle);
MockedRestProvider.Verify(p => p.PostData(It.Is<string>(c => c.ToLower().StartsWith("http://service.nzbdrone.com/")), It.Is<ParseErrorReport>(c => c.Title == badTitle)), Times.Once());
MockedRestProvider.Verify(p => p.PostData(It.Is<string>(c => c.ToLower().StartsWith("http://services.nzbdrone.com/")), It.Is<ParseErrorReport>(c => c.Title == badTitle)), Times.Once());
}
[Test]
@ -64,5 +64,14 @@ namespace NzbDrone.Common.Test
MockedRestProvider.Verify(p => p.PostData(It.IsAny<string>(), It.Is<ParseErrorReport>(c => c.Title == "title 2")), Times.Once());
}
[Test]
public void report_parse_error()
{
ReportingService.RestProvider = new RestProvider(new EnviromentProvider());
ReportingService.ReportParseError("Test error");
}
}
}

View File

@ -86,7 +86,7 @@ namespace NzbDrone.Common
fileTarget.ConcurrentWriteAttemptDelay = 50;
fileTarget.ConcurrentWriteAttempts = 200;
fileTarget.Layout = @"${date:format=yy-M-d HH\:mm\:ss.f}|${replace:searchFor=NzbDrone.:replaceWith=:inner=${logger}}|${message}|${exception:format=ToString}";
fileTarget.Layout = @"${date:format=yy-M-d HH\:mm\:ss.f}|${replace:searchFor=NzbDrone.:replaceWith=:inner=${logger}}|${level}|${message}|${exception:format=ToString}";
return fileTarget;
}

View File

@ -57,7 +57,7 @@
<Compile Include="ConsoleProvider.cs" />
<Compile Include="Contract\ExceptionReport.cs" />
<Compile Include="Contract\ReportBase.cs" />
<Compile Include="Contract\ParseErrorRequ.cs" />
<Compile Include="Contract\ParseErrorReport.cs" />
<Compile Include="NlogTargets\RemoteTarget.cs" />
<Compile Include="IISProvider.cs" />
<Compile Include="Model\AuthenticationType.cs" />

View File

@ -10,9 +10,9 @@ namespace NzbDrone.Common
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private const string SERVICE_URL = "http://service.nzbdrone.com/reporting";
private const string PARSE_URL = SERVICE_URL + "/parser";
private const string EXCEPTION_URL = SERVICE_URL + "/exception";
private const string SERVICE_URL = "http://services.nzbdrone.com/reporting";
private const string PARSE_URL = SERVICE_URL + "/ParseError";
private const string EXCEPTION_URL = SERVICE_URL + "/ReportException";
public static RestProvider RestProvider { get; set; }
private static readonly HashSet<string> parserErrorCache = new HashSet<string>();

View File

@ -1,7 +1,9 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using NLog;
using Newtonsoft.Json;
using Ninject;
using NzbDrone.Common.Contract;
@ -11,6 +13,9 @@ namespace NzbDrone.Common
public class RestProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly EnviromentProvider _enviromentProvider;
@ -25,7 +30,7 @@ namespace NzbDrone.Common
}
private const int TIMEOUT = 10000;
private const int TIMEOUT = 15000;
private const string METHOD = "POST";
public virtual void PostData(string url, ReportBase reportBase)
@ -40,28 +45,36 @@ namespace NzbDrone.Common
private static void PostData(string url, object message)
{
var json = JsonConvert.SerializeObject(message);
try
{
var json = JsonConvert.SerializeObject(message);
var request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = TIMEOUT;
var request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = TIMEOUT;
request.Proxy = WebRequest.DefaultWebProxy;
request.Proxy = WebRequest.DefaultWebProxy;
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = METHOD;
request.ContentType = "application/json";
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = METHOD;
request.ContentType = "application/json";
byte[] postBytes = Encoding.UTF8.GetBytes(json);
request.ContentLength = postBytes.Length;
byte[] postBytes = Encoding.UTF8.GetBytes(json);
request.ContentLength = postBytes.Length;
var requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
var requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
var response = (HttpWebResponse)request.GetResponse();
var streamreader = new StreamReader(response.GetResponseStream());
streamreader.Close();
var response = (HttpWebResponse)request.GetResponse();
var streamreader = new StreamReader(response.GetResponseStream());
streamreader.Close();
}
catch (Exception e)
{
e.Data.Add("URL", url);
throw;
}
}
}
}

View File

@ -0,0 +1,26 @@
using System.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Services.Service.App_Start;
[assembly: WebActivator.PreApplicationStartMethod(typeof(Logging), "PreStart")]
namespace NzbDrone.Services.Service.App_Start
{
public static class Logging
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public static void PreStart()
{
LogConfiguration.RegisterUdpLogger();
LogConfiguration.RegisterFileLogger("${basedir}/_logs/${shortdate}.log", LogLevel.Trace);
LogConfiguration.Reload();
logger.Info("Logger has been configured. (App Start)");
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Data;
using Migrator.Framework;
namespace NzbDrone.Services.Service.Migrations
{
[Migration(20120205)]
public class Migration20120205 : Migration
{
public override void Up()
{
Database.ChangeColumn("ParseErrorReports", MigrationsHelper.VersionColumn);
Database.ChangeColumn("ExceptionReports", MigrationsHelper.VersionColumn);
}
public override void Down()
{
throw new NotImplementedException();
}
}
}

View File

@ -46,7 +46,7 @@ namespace NzbDrone.Services.Service.Migrations
return String.Format("IX_{0}_{1}", tableName, String.Join("_", columns));
}
public static readonly Column VersionColumn = new Column("Version", DbType.String, 10, ColumnProperty.NotNull);
public static readonly Column VersionColumn = new Column("Version", DbType.String, 50, ColumnProperty.NotNull);
public static readonly Column ProductionColumn = new Column("IsProduction", DbType.Boolean, ColumnProperty.NotNull);
public static readonly Column TimestampColumn = new Column("TimeStamp", DbType.DateTime, ColumnProperty.NotNull);
public static readonly Column UGuidColumn = new Column("UGuid", DbType.Guid, ColumnProperty.Null);

View File

@ -108,6 +108,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\Logging.cs" />
<Compile Include="App_Start\NinjectMVC3.cs" />
<Compile Include="Datastore\Connection.cs" />
<Compile Include="Controllers\DailySeriesController.cs" />
@ -119,6 +120,7 @@
</Compile>
<Compile Include="JsonModelBinder.cs" />
<Compile Include="Migrations\Migration20120203.cs" />
<Compile Include="Migrations\Migration20120205.cs" />
<Compile Include="Migrations\Migration20120201.cs" />
<Compile Include="Migrations\MigrationHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -16,7 +16,7 @@
-->
<system.web>
<compilation debug="false" xdt:Transform="Replace" />
<customErrors mode="RemoteOnly" xdt:Transform="Replace"/>
<!--<customErrors mode="RemoteOnly" xdt:Transform="Replace"/>-->
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.

View File

@ -28,7 +28,7 @@ namespace NzbDrone.Services.Tests
{
IsProduction = true,
Title = "MyTitle",
Version = "1.1.2.3",
Version = "1.1.2.323456",
UGuid = Guid.NewGuid()
};
}
@ -38,7 +38,7 @@ namespace NzbDrone.Services.Tests
return new ExceptionReport
{
IsProduction = true,
Version = "1.1.2.3",
Version = "1.1.2.323456",
UGuid = Guid.NewGuid(),
Logger = "NzbDrone.Logger.Name",
LogMessage = "Long message Long message Long messageLong messageLong messageLong messageLong messageLong messageLong messageLong messageLong message",