Skip to content

Instantly share code, notes, and snippets.

View optical's full-sized avatar

Jared Klopper optical

View GitHub Profile
framework: auto-detect
strategy: min
source https://api.nuget.org/v3/index.json
nuget Npgsql ~> 3.1.9 version_in_path: true
nuget Serilog ~> 2.2 version_in_path: true
nuget Serilog.Sinks.Literate ~> 2.0 version_in_path: true
nuget Serilog.Sinks.TextWriter ~> 2.1 version_in_path: true
nuget SerilogAnalyzer ~> 0.9.0 version_in_path: true
nuget System.Collections.Immutable ~> 1.3.1 version_in_path: true
framework: auto-detect
strategy: min
source https://api.nuget.org/v3/index.json
nuget Npgsql ~> 3.1.9 version_in_path: true
nuget Serilog ~> 2.2 version_in_path: true
nuget Serilog.Sinks.Literate ~> 2.0 version_in_path: true
nuget Serilog.Sinks.TextWriter ~> 2.1 version_in_path: true
nuget SerilogAnalyzer ~> 0.9.0 version_in_path: true
nuget System.Collections.Immutable ~> 1.3.1 version_in_path: true
SelfLog.Enable(Console.WriteLine);
using (LogContext.PushProperty("SomeProperty", "SomeValue")) {
// Works, but also raises a self log message
Log.Information("Lets look at a property {SomeProperty}");
}
@optical
optical / SourceContextSink.cs
Last active November 9, 2016 21:19
Serilog sink which writes events to a filename based on the source context property
public class SourceContextSink : ILogEventSink {
private readonly string _folderPath;
private readonly ConcurrentDictionary<string, Lazy<FileSink>> _fileSinks;
public SourceContextSink(string folderPath) {
_folderPath = folderPath;
_fileSinks = new ConcurrentDictionary<string, Lazy<FileSink>>();
}
public void Emit(LogEvent logEvent) {
@optical
optical / Main.cs
Created October 31, 2016 21:04
Log Event level formatting issue in Serilog
using System;
using System.Globalization;
using Serilog;
using Serilog.Events;
namespace SeriLogTest {
public class LogLevelFormatter : IFormatProvider, ICustomFormatter {
private readonly IFormatProvider _innerFormatProvider;
@optical
optical / Main.cs
Created September 7, 2016 20:17
Custom enum formatting with Serilog
using System;
using System.Globalization;
using Serilog;
namespace SeriLogTest {
enum Size {
Small,
Medium,
Large