Skip to content
Permalink
Browse files

Demonstrate use of SelfLog to output Serilog internal exceptions, usi…

…ng a bad Seq URL.
  • Loading branch information...
Adam Grande
Adam Grande committed Nov 1, 2016
1 parent a57139d commit 5d7b765f9c266bdebe0bee7a2bae4732c18ae646
Showing with 30 additions and 8 deletions.
  1. +3 −1 .gitignore
  2. +26 −6 SerilogPoc/App_Start/IoCConfig.cs
  3. +1 −1 SerilogPoc/Web.config
@@ -242,4 +242,6 @@ ModelManifest.xml
.paket/paket.exe

# FAKE - F# Make
.fake/
.fake/

serilogexceptions.log
@@ -1,6 +1,13 @@
using System.Configuration;
using System;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Net.Mime;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using Autofac;
using Autofac.Core.Activators.Reflection;
using Autofac.Integration.Mvc;
using AutofacSerilogIntegration;
using Serilog;
@@ -14,18 +21,31 @@ public static class IoCConfig

public static void Configure()
{
var builder = new ContainerBuilder();

ConfigureSerilog(builder);

builder.RegisterControllers(typeof(WebApiApplication).Assembly);

Container = builder.Build();

DependencyResolver.SetResolver(new AutofacDependencyResolver(Container));
}

private static void ConfigureSerilog(ContainerBuilder builder)
{
var location = HttpRuntime.AppDomainAppPath;
var file = File.CreateText(location + "\\serilogexceptions.log");

Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file));

var logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.With<HttpRequestIdEnricher>()
.WriteTo.Seq(ConfigurationManager.AppSettings["SeqUrl"])
.CreateLogger();

var builder = new ContainerBuilder();
builder.RegisterLogger(logger);
builder.RegisterControllers(typeof(WebApiApplication).Assembly);

Container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(Container));
}
}
}
@@ -11,7 +11,7 @@
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

<!-- This is the default installation URL of the installation of Seq. Feel free to adjust to whatever site/port you want. -->
<add key="SeqUrl" value="http://localhost:5341/" />
<add key="SeqUrl" value="http://iamabadurl:5341/" />

</appSettings>
<system.web>

0 comments on commit 5d7b765

Please sign in to comment.
You can’t perform that action at this time.