Skip to content

Instantly share code, notes, and snippets.

@beppemarazzi
beppemarazzi / JsonDocumentDestructuringPolicy.cs
Last active October 23, 2023 18:39 — forked from nblumhardt/JsonDocumentDestructuringPolicy.cs
Properly serialize System.Text.Json documents with Serilog
using System;
using System.Linq;
using System.Text.Json;
using Serilog.Core;
using Serilog.Events;
class JsonDocumentDestructuringPolicy : IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory _, out LogEventPropertyValue result)
{
@tsimbalar
tsimbalar / README.md
Last active April 20, 2019 21:50
Pino js tool to make raw pino output compatible with Seq / GELF ingestion through docker

This is a small tool that allows transforms logs written with pino in newline-delimited JSON on the standard output to the Compact Log Event Format (CLEF) supported by the Seq logging server.

Typical use case for this is :

  • write your logs with pino how you would normally do it
logger.info({some: 'extra', context:'info'}, 'this is the message');
logger.info({user: 'John', amount:'2345', extra: 'other info'}, '{user} just spent {amount} euros on the website');
@bradwilson
bradwilson / vs2017.ps1
Last active January 23, 2018 19:05
VS 2017 PowerShell script; if you need invoke-cmdscript, it's here: https://gist.github.com/bradwilson/3fca203370d54304eff1cce21ffc32aa
param(
[string]$edition,
[switch]$noWeb = $false
)
# Try and find a version of Visual Studio in the expected location, since the VS150COMNTOOLS environment variable isn't there any more
$basePath = join-path (join-path ${env:ProgramFiles(x86)} "Microsoft Visual Studio") "2017"
if ((test-path $basePath) -eq $false) {
write-warning "Visual Studio 2017 is not installed."
@dennisroche
dennisroche / Install-Seq.ps1
Last active February 23, 2017 19:30
Download and install Seq (https://getseq.net/). Can be used by Azure Resource Manager template. Use RawGit to access the file with proper Content-Type headers - https://rawgit.com/
[CmdletBinding()]
param (
[string]$SeqVersion,
[string]$SeqInstanceName,
[string]$SeqPort
)
$installBasePath = "C:\Install\"
$seqDataPath = "C:\ProgramData\Seq"

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@gertjvr
gertjvr / CorrelationExample.cs
Last active October 14, 2022 14:28
MT3 + Serilog CorrelationId Enricher.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Threading.Tasks;
using MassTransit;
using MassTransit.Configurators;
using MassTransit.PipeBuilders;
using MassTransit.PipeConfigurators;
using MassTransit.Pipeline;
[Fact]
void Main()
{
var cb = new ContainerBuilder();
cb.RegisterModule(new LoggingModule<log4net.ILog>(log4net.LogManager.GetLogger));
cb.RegisterModule(new LoggingModule<Serilog.ILogger>(Serilog.Log.ForContext));
cb.RegisterType<HasLogProperty>();
cb.RegisterType<HasLogCtor>();
@liammclennan
liammclennan / README.md
Last active April 17, 2020 18:29
RedisMQ

RedisMQ

Many people use Redis for a simple message broker. RedisMQ is a trivial layer on Redis and StackExchange.Redis that probably does not work. It provides two simple messaging patterns:

Publish / subscribe

A publisher publishes messages. 0, 1 or more consumers subscribe to the messages.

@nguerrera
nguerrera / DelegateToStaticWithFirstArg.cs
Last active August 29, 2015 14:05
Creating a delegate bound to a static method with first argument in verifiable IL
// And this program can be writen in C# after all if you use an extension method!
// (And the codegen is exactly as the optimal hand-written IL below.)
//
// Thanks to Vladimir Sadov on the compiler team for teaching me about it!
static class Program
{
static void Main()
{
var f = new Func<string>("World".StaticMethod);
@lukehorvat
lukehorvat / interceptors.coffee
Last active December 23, 2015 02:49
An example of how to use request/response interceptors in AngularJS 1.2 for consistent API interactions. This code does two things: 1) Automatic injection of the user auth token in all API requests. 2) Automatic event firing when the user receives an API response indicating a 401 (unauthorised) request.
.config ($httpProvider) ->
$httpProvider.interceptors.push ($q, $rootScope, apiUrl, authToken) ->
request: (config) ->
# Intercept API requests and inject the auth token.
config.headers["X-Auth-Token"] = authToken if config.url.indexOf(apiUrl) is 0 and authToken?
config or $q.when config
responseError: (response) ->
# Intercept unauthorised API responses and fire an event.