Skip to content

Instantly share code, notes, and snippets.

@nblumhardt
nblumhardt / gist:8914175
Created February 10, 2014 11:17
An alternative to stack walking to add caller names to Serilog events
public static class LoggerExtensions
{
public static ILogger ForHere(
this ILogger logger,
[CallerFilePath] string sourceFile = null,
[CallerLineNumber] int sourceLine = 0)
{
return logger
.ForContext("SourceFile", sourceFile)
.ForContext("SourceLine", sourceLine);
## --------------------------------------------------------------------------------------
## Configuration
## --------------------------------------------------------------------------------------
$ConfirmPreference = "None"
$isEnabled = $OctopusParameters["Octopus.Action.IISWebSite.CreateOrUpdateWebSite"]
if (!$isEnabled -or ![Bool]::Parse($isEnabled))
{
exit 0
@nblumhardt
nblumhardt / gist:07c8046ffdcbd3d6b1fa
Created May 18, 2014 11:08
Seq configuration via AppSettings

1. Install Serilog.Extras.AppSettings

PM> Install-Package Serilog.Extras.AppSettings

2. Add the 'read' method to logger config

... = new LoggerConfiguration()
@nblumhardt
nblumhardt / Body.tmpl
Created July 31, 2014 04:43
Showing step summary in a deployment email with Octopus Deploy
<h3>Task summary:</h3>
<ol>
#{each step in Octopus.Step}
<li>#{step.Name | HtmlEscape} &mdash; <strong>#{step.Status.Code}</strong> #{step.Status.Error | HtmlEscape}
#{if step.Status.ErrorDetail}
<pre>#{step.Status.ErrorDetail | HtmlEscape}</pre>
#{/if}
</li>
#{/each}
</ol>
@nblumhardt
nblumhardt / NoResourceTrackingInAutofac.cs
Created January 7, 2011 23:28
Disable disposable resource tracking for a service in Autofac
var builder = new ContainerBuilder();
// The thing we want to create haphazardly without ever
// disposing it or any of its dependencies:
builder.RegisterType<Foo>()
.Named<IFoo>("untracked");
// Owned<T> is itself untracked (i.e. disposal is up to the
// owner.) Since we just let the Owned<IFoo> slip away, it
var module = angular.module('octopusApp.projects');
module.controller('ProjectReleaseController', function ($scope, busy, $routeParams, pageTitle, octopusRepository, $q) {
var isLoading = $scope.isLoading = busy.create();
var projectId = $routeParams["id"];
var releaseVersion = $routeParams["version"];
var project, release, deploymentProcess;
isLoading.promise(octopusRepository.Projects.get(projectId).then(function (project2) {
project = project2;
@nblumhardt
nblumhardt / SampleReactor.cs
Created December 14, 2013 03:47
Just a simple example to show how plugins ("apps") consume data from the stream
using Seq.Apps;
using Seq.Apps.LogEvents;
namespace Seq.BuiltIn.SampleApp
{
public class SampleReactor : Reactor, ISubscribeTo<LogEventData>
{
public void On(Event<LogEventData> evt)
{
if (evt.Data.Level == LogEventLevel.Error)
using Seq.Apps;
using Seq.Apps.LogEvents;
using System;
using System.Linq;
namespace Seq.Sample.SlidingWindows
{
/// <summary>
/// Counts events in a sliding time window, writing a message back to the
/// stream when a set threshold is reached.
@nblumhardt
nblumhardt / SerilogStructuredDataToolkit.cs
Last active June 3, 2016 01:53
Visitor pattern implementation for exploring/printing/rewriting structured data from Serilog
using System;
using System.Collections.Generic;
using System.Linq;
using Serilog.Events;
namespace SerilogStructuredDataToolkit
{
public abstract class LogEventPropertyValueVisitor<TResult>
{
public virtual TResult Visit(LogEventPropertyValue value)
@nblumhardt
nblumhardt / Program.cs
Created October 3, 2016 21:25
Render JSON data using MessageTemplates
using System;
using System.Linq;
using MessageTemplates.Core;
using MessageTemplates.Parsing;
using MessageTemplates.Structure;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace MessageTemplateRenderer
{