Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gauffininteractive committed Feb 16, 2017
2 parents 3f53e08 + 7e597d6 commit 36a8e20
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 251 deletions.
Expand Up @@ -8,6 +8,9 @@ public class ErrorReportEntityMapper : CrudEntityMapper<ErrorReportEntity>
{
public ErrorReportEntityMapper() : base("ErrorReports")
{
Property(x => x.Id)
.PrimaryKey(true);

Property(x => x.Exception)
.ToPropertyValue(EntitySerializer.Deserialize<ErrorReportException>)
.ToColumnValue(EntitySerializer.Serialize);
Expand Down

This file was deleted.

Expand Up @@ -27,7 +27,7 @@ public virtual async Task<int> GetAverageReportCountAsync(int applicationId)
{
cmd.CommandText = @"SELECT
[Day] = DATENAME(WEEKDAY, createdatutc),
Totals = COUNT(*)
Totals = cast (COUNT(*) as int)
FROM errorreports
WHERE applicationid=@appId
GROUP BY
Expand All @@ -38,7 +38,7 @@ GROUP BY
{
while (await reader.ReadAsync())
{
numbers.Add((int) reader[0]);
numbers.Add((int) reader[1]);
}
}
numbers.Sort();
Expand Down
Expand Up @@ -120,7 +120,6 @@
<Compile Include="Core\Incidents\Queries\GetReportListResultItemMapper.cs" />
<Compile Include="Core\Notifications\NotificationRepository.cs" />
<Compile Include="Core\Notifications\UserNotificationSettingsMap.cs" />
<Compile Include="Core\ReportSpikes\ReportSpikesRepository.cs" />
<Compile Include="Core\Reports\ErrorReportDtoMapper.cs" />
<Compile Include="Core\Reports\ErrorReportRepository.cs" />
<Compile Include="Core\Users\ApplicationTeamMemberMapper.cs" />
Expand Down
@@ -1,6 +1,7 @@
using System;
using System.Web.Mvc;
using OneTrueError.App.Configuration;
using OneTrueError.Client;
using OneTrueError.Infrastructure;
using OneTrueError.Infrastructure.Configuration;
using OneTrueError.Web.Areas.Admin.Models;
Expand Down Expand Up @@ -65,6 +66,7 @@ public ActionResult Errors(ErrorTrackingViewModel model)
settings.ContactEmail = model.ContactEmail;
settings.InstallationId = model.InstallationId;
ConfigurationStore.Instance.Store(settings);
WebApiApplication.ReportToOneTrueError = model.ActivateTracking;
return Redirect(Url.GetNextWizardStep());
}

Expand Down
20 changes: 20 additions & 0 deletions src/Server/OneTrueError.Web/Global.asax.cs
@@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using Griffin.Signals;
using log4net;
using log4net.Config;
using OneTrueError.Client;
using OneTrueError.Client.Contracts;
using OneTrueError.Infrastructure;
using OneTrueError.SqlServer;
using OneTrueError.Web.Infrastructure.Logging;
Expand All @@ -15,6 +18,7 @@ namespace OneTrueError.Web
public class WebApiApplication : HttpApplication
{
private static readonly ILog _logger;
public static bool ReportToOneTrueError;

static WebApiApplication()
{
Expand Down Expand Up @@ -47,6 +51,22 @@ private void Application_Error(object sender, EventArgs e)
data = reader.ReadToEnd();
}
_logger.Error("Request + " + Request.Url + ", data" + data, exception);

if (!ReportToOneTrueError)
return;

var properties = new Dictionary<string, string>
{
{"Url", Request.Url.ToString()},
{"HttpMethod", Request.HttpMethod}
};
if (Request.UrlReferrer != null)
properties.Add("Referer", Request.UrlReferrer.ToString());
if (data.Length < 30000)
properties.Add("Body", data);
properties.Add("OneTrueTags", "unhandled-exception");
var collection = new ContextCollectionDTO("Request", properties);
OneTrue.Report(exception, collection);
}

private static void OnSignalRaised(object sender, SignalRaisedEventArgs e)
Expand Down
@@ -1,12 +1,17 @@
using System.Web.Http.ExceptionHandling;
using System.Collections.Generic;
using System.Web.Http.ExceptionHandling;
using log4net;
using OneTrueError.Client;
using OneTrueError.Client.Contracts;

namespace OneTrueError.Web.Infrastructure.Logging
{
internal class WebApiLogger : ExceptionLogger
{
private readonly ILog _logger = LogManager.GetLogger(typeof(WebApiLogger));

public string ReportToOneTrueError { get; set; }

public override void Log(ExceptionLoggerContext context)
{
var data = "";
Expand All @@ -17,6 +22,21 @@ public override void Log(ExceptionLoggerContext context)

_logger.Error("Request + " + context.Request.RequestUri + ", data" + data, context.Exception);
_logger.Error(context.Exception);

if (!WebApiApplication.ReportToOneTrueError)
return;

var properties = new Dictionary<string, string>
{
{"Url", context.Request.RequestUri.ToString()},
{"HttpMethod", context.Request.Method.Method}
};
if (context.Request.Headers.Referrer != null)
properties.Add("Referer", context.Request.Headers.Referrer.ToString());
if (data.Length < 30000)
properties.Add("Body", data);
var collection = new ContextCollectionDTO("Request", properties);
OneTrue.Report(context.Exception, collection);
base.Log(context);
}
}
Expand Down

0 comments on commit 36a8e20

Please sign in to comment.