Permalink
Browse files

Add logging

  • Loading branch information...
petermorlion committed Jan 2, 2019
1 parent 42be49b commit 38779c20e56cf7d417af773326c52b0240dc33f7
Showing with 22,767 additions and 5 deletions.
  1. +1 −1 KotProno2/App_Start/FilterConfig.cs
  2. +33 −4 KotProno2/App_Start/Startup.Autofac.cs
  3. +7 −0 KotProno2/Global.asax.cs
  4. +17 −0 KotProno2/KotProno2.csproj
  5. +15 −0 KotProno2/MvcExceptionFilter.cs
  6. +24 −0 KotProno2/WebApiExceptionFilter.cs
  7. +5 −0 KotProno2/packages.config
  8. BIN packages/Microsoft.ApplicationInsights.2.5.1/.signature.p7s
  9. BIN packages/Microsoft.ApplicationInsights.2.5.1/Microsoft.ApplicationInsights.2.5.1.nupkg
  10. BIN packages/Microsoft.ApplicationInsights.2.5.1/lib/net45/Microsoft.ApplicationInsights.dll
  11. BIN packages/Microsoft.ApplicationInsights.2.5.1/lib/net46/Microsoft.ApplicationInsights.dll
  12. BIN packages/Microsoft.ApplicationInsights.2.5.1/lib/netstandard1.3/Microsoft.ApplicationInsights.dll
  13. BIN packages/Serilog.2.7.1/.signature.p7s
  14. BIN packages/Serilog.2.7.1/Serilog.2.7.1.nupkg
  15. BIN packages/Serilog.2.7.1/lib/net45/Serilog.dll
  16. +4,555 −0 packages/Serilog.2.7.1/lib/net45/Serilog.xml
  17. BIN packages/Serilog.2.7.1/lib/net46/Serilog.dll
  18. +4,555 −0 packages/Serilog.2.7.1/lib/net46/Serilog.xml
  19. BIN packages/Serilog.2.7.1/lib/netstandard1.0/Serilog.dll
  20. +4,555 −0 packages/Serilog.2.7.1/lib/netstandard1.0/Serilog.xml
  21. BIN packages/Serilog.2.7.1/lib/netstandard1.3/Serilog.dll
  22. +4,555 −0 packages/Serilog.2.7.1/lib/netstandard1.3/Serilog.xml
  23. BIN packages/Serilog.Sinks.ApplicationInsights.2.6.0/.signature.p7s
  24. BIN packages/Serilog.Sinks.ApplicationInsights.2.6.0/Serilog.Sinks.ApplicationInsights.2.6.0.nupkg
  25. BIN packages/Serilog.Sinks.ApplicationInsights.2.6.0/lib/net45/Serilog.Sinks.ApplicationInsights.dll
  26. BIN .../Serilog.Sinks.ApplicationInsights.2.6.0/lib/netstandard1.3/Serilog.Sinks.ApplicationInsights.dll
  27. BIN .../Serilog.Sinks.ApplicationInsights.2.6.0/lib/netstandard1.6/Serilog.Sinks.ApplicationInsights.dll
  28. BIN packages/Serilog.Sinks.Console.3.1.1/.signature.p7s
  29. BIN packages/Serilog.Sinks.Console.3.1.1/Serilog.Sinks.Console.3.1.1.nupkg
  30. BIN packages/Serilog.Sinks.Console.3.1.1/lib/net45/Serilog.Sinks.Console.dll
  31. +287 −0 packages/Serilog.Sinks.Console.3.1.1/lib/net45/Serilog.Sinks.Console.xml
  32. BIN packages/Serilog.Sinks.Console.3.1.1/lib/netcoreapp1.1/Serilog.Sinks.Console.dll
  33. +287 −0 packages/Serilog.Sinks.Console.3.1.1/lib/netcoreapp1.1/Serilog.Sinks.Console.xml
  34. BIN packages/Serilog.Sinks.Console.3.1.1/lib/netstandard1.3/Serilog.Sinks.Console.dll
  35. +287 −0 packages/Serilog.Sinks.Console.3.1.1/lib/netstandard1.3/Serilog.Sinks.Console.xml
  36. BIN packages/System.Diagnostics.DiagnosticSource.4.4.0/.signature.p7s
  37. +23 −0 packages/System.Diagnostics.DiagnosticSource.4.4.0/LICENSE.TXT
  38. BIN packages/System.Diagnostics.DiagnosticSource.4.4.0/System.Diagnostics.DiagnosticSource.4.4.0.nupkg
  39. +226 −0 packages/System.Diagnostics.DiagnosticSource.4.4.0/THIRD-PARTY-NOTICES.TXT
  40. BIN packages/System.Diagnostics.DiagnosticSource.4.4.0/lib/net45/System.Diagnostics.DiagnosticSource.dll
  41. +789 −0 packages/System.Diagnostics.DiagnosticSource.4.4.0/lib/net45/System.Diagnostics.DiagnosticSource.xml
  42. BIN packages/System.Diagnostics.DiagnosticSource.4.4.0/lib/net46/System.Diagnostics.DiagnosticSource.dll
  43. +825 −0 packages/System.Diagnostics.DiagnosticSource.4.4.0/lib/net46/System.Diagnostics.DiagnosticSource.xml
  44. 0 packages/System.Diagnostics.DiagnosticSource.4.4.0/lib/netcoreapp2.0/_._
  45. BIN ...tem.Diagnostics.DiagnosticSource.4.4.0/lib/netstandard1.1/System.Diagnostics.DiagnosticSource.dll
  46. +486 −0 ...tem.Diagnostics.DiagnosticSource.4.4.0/lib/netstandard1.1/System.Diagnostics.DiagnosticSource.xml
  47. BIN ...tem.Diagnostics.DiagnosticSource.4.4.0/lib/netstandard1.3/System.Diagnostics.DiagnosticSource.dll
  48. +748 −0 ...tem.Diagnostics.DiagnosticSource.4.4.0/lib/netstandard1.3/System.Diagnostics.DiagnosticSource.xml
  49. BIN ...tics.DiagnosticSource.4.4.0/lib/portable-net45+win8+wpa81/System.Diagnostics.DiagnosticSource.dll
  50. +486 −0 ...tics.DiagnosticSource.4.4.0/lib/portable-net45+win8+wpa81/System.Diagnostics.DiagnosticSource.xml
  51. 0 packages/System.Diagnostics.DiagnosticSource.4.4.0/ref/netcoreapp2.0/_._
  52. 0 packages/System.Diagnostics.DiagnosticSource.4.4.0/useSharedDesignerContext.txt
  53. +1 −0 packages/System.Diagnostics.DiagnosticSource.4.4.0/version.txt
@@ -6,7 +6,7 @@ public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new MvcExceptionFilter());
}
}
}
@@ -1,30 +1,59 @@
using System.Web.Http;
using System.Configuration;
using System.Diagnostics.Eventing.Reader;
using System.Web.Http;
using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Mvc;
using Autofac.Integration.WebApi;
using KotProno2.EntityFramework;
using Microsoft.ApplicationInsights;
using Owin;
using Serilog;

namespace KotProno2
{
public partial class Startup
{
private static TelemetryClient _telemetryClient;

public static TelemetryClient TelemetryClient => _telemetryClient ?? (_telemetryClient = new TelemetryClient
{
InstrumentationKey = ConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"]
});

public void ConfigureAutofac(IAppBuilder app)
{
var builder = new ContainerBuilder();

builder.RegisterApiControllers(typeof(MvcApplication).Assembly);
builder.RegisterControllers(typeof(MvcApplication).Assembly);

builder.RegisterType<MatchesDbContext>().InstancePerRequest();

var log = new LoggerConfiguration()
#if DEBUG
.WriteTo.Console()
#else
.WriteTo.ApplicationInsightsEvents(TelemetryClient)
#endif
.CreateLogger();
builder.RegisterInstance(log).As<ILogger>();

builder.RegisterType<WebApiExceptionFilter>().AsWebApiExceptionFilterFor<ApiController>().InstancePerRequest();

builder.RegisterFilterProvider();

var config = GlobalConfiguration.Configuration;
builder.RegisterWebApiFilterProvider(config);

var container = builder.Build();

DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

app.UseAutofacMiddleware(container);
app.UseAutofacMvc();

var config = GlobalConfiguration.Configuration;
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
}
}
@@ -24,7 +24,14 @@ protected void Application_Start()
protected void Application_Error()
{
var e = Server.GetLastError();
}

protected void Application_End()
{
#if DEBUG
#else
Startup.TelemetryClient.Flush();
#endif
}
}
}
@@ -68,6 +68,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.6.1.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ApplicationInsights, Version=2.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.ApplicationInsights.2.5.1\lib\net46\Microsoft.ApplicationInsights.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Data.Edm, Version=5.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -84,9 +87,21 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.7.1\lib\net46\Serilog.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.ApplicationInsights, Version=2.6.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.ApplicationInsights.2.6.0\lib\net45\Serilog.Sinks.ApplicationInsights.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.Console, Version=3.1.1.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.Console.3.1.1\lib\net45\Serilog.Sinks.Console.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.4.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.0\lib\net45\System.Net.Http.Formatting.dll</HintPath>
@@ -220,6 +235,8 @@
<Compile Include="Controllers\TopScorersController.cs" />
<Compile Include="Controllers\TournamentsController.cs" />
<Compile Include="EntityFramework\MatchesDbContext.cs" />
<Compile Include="MvcExceptionFilter.cs" />
<Compile Include="WebApiExceptionFilter.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
@@ -0,0 +1,15 @@
using System.Web.Mvc;
using Serilog;

namespace KotProno2
{
public class MvcExceptionFilter : IExceptionFilter
{
public ILogger Logger { get; set; }

public void OnException(ExceptionContext filterContext)
{
Logger.Error(filterContext.Exception, "An unhandled exception occurred.");
}
}
}
@@ -0,0 +1,24 @@
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Filters;
using Autofac.Integration.WebApi;
using Serilog;

namespace KotProno2
{
public class WebApiExceptionFilter : IAutofacExceptionFilter
{
private readonly ILogger _logger;

public WebApiExceptionFilter(ILogger logger)
{
_logger = logger;
}

public Task OnExceptionAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
{
_logger.Error(actionExecutedContext.Exception, "An unhandled exception occurred.");
return Task.FromResult(0);
}
}
}
@@ -10,6 +10,7 @@
<package id="Autofac.WebApi2" version="4.0.0" targetFramework="net461" />
<package id="Autofac.WebApi2.Owin" version="4.0.0" targetFramework="net461" />
<package id="EntityFramework" version="6.1.0" targetFramework="net45" />
<package id="Microsoft.ApplicationInsights" version="2.5.1" targetFramework="net461" />
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
@@ -39,6 +40,10 @@
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
<package id="Q" version="1.0.0" targetFramework="net45" />
<package id="Serilog" version="2.7.1" targetFramework="net461" />
<package id="Serilog.Sinks.ApplicationInsights" version="2.6.0" targetFramework="net461" />
<package id="Serilog.Sinks.Console" version="3.1.1" targetFramework="net461" />
<package id="System.Diagnostics.DiagnosticSource" version="4.4.0" targetFramework="net461" />
<package id="System.Spatial" version="5.6.1" targetFramework="net45" />
<package id="WebActivator" version="1.5.3" targetFramework="net45" />
<package id="WebGrease" version="1.5.2" targetFramework="net45" />
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit 38779c2

Please sign in to comment.