Skip to content

Instantly share code, notes, and snippets.

View stephenpatten's full-sized avatar

Stephen Patten stephenpatten

View GitHub Profile
Initialize the logger in the constructor:
class SomethingAbstract
{
protected ILogger Log { get; }
protected SomethingAbstract()
{
Log = Log.ForContext(GetType());
}
@stephenpatten
stephenpatten / Logstash-log4net-README.md
Created March 11, 2018 01:25 — forked from junxy/Logstash-log4net-README.md
Logstash 2.1.x config for log4net logs.
<!- .... ->
<log4net>    
    <appender name="RollingLogFileAppenderLogstash" type="log4net.Appender.RollingFileAppender">
      <encoding value="utf-8" />
      <!--该目录必需有 IIS用户 写权限-->
      <file value="X:/var/log/[app_name]/logfile.log" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
@stephenpatten
stephenpatten / README.md
Created February 17, 2018 05:33 — forked from magnetikonline/README.md
NSSM - the Non-Sucking Service Manager cheatsheet.
@stephenpatten
stephenpatten / unzip.ps1
Created January 26, 2018 21:50 — forked from nachivpn/unzip.ps1
Unzip a file in powershell by overwriting existing files
function Unzip($zipfile, $outdir)
{
Add-Type -AssemblyName System.IO.Compression.FileSystem
$archive = [System.IO.Compression.ZipFile]::OpenRead($zipfile)
foreach ($entry in $archive.Entries)
{
$entryTargetFilePath = [System.IO.Path]::Combine($outdir, $entry.FullName)
$entryDir = [System.IO.Path]::GetDirectoryName($entryTargetFilePath)
#Ensure the directory of the archive entry exists
@stephenpatten
stephenpatten / batch.bat
Created January 12, 2018 05:11 — forked from bangonkali/batch.bat
Attaching Notepad++ to git commit editor.
git config core.editor "'C:\Program Files (x86)\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
private static ILogger ConfigureLogger()
{
// By sharing between the Seq sink and logger itself,
// Seq API keys can be used to control the level of the whole logging pipeline.
var levelSwitch = new LoggingLevelSwitch();
var appSettings = ConfigurationManager.AppSettings;
var filePath =
$"{ConfigurationManager.AppSettings["serilog:Log:FilePath"]}\\DocumentReceiver_{Environment.MachineName}_.txt";
@stephenpatten
stephenpatten / DisablingServicesOnServer2016wDE.ps1
Created December 7, 2017 20:27 — forked from hpaul-osi/DisablingServicesOnServer2016wDE.ps1
Disable unnecessary services that on Windows Server 2016 Desktop Experience (based on MS Security Blog recommendations)
# Disable extraneous services on Server 2016 Desktop Experience
# https://blogs.technet.microsoft.com/secguide/2017/05/29/guidance-on-disabling-system-services-on-windows-server-2016-with-desktop-experience/
Configuration DisablingServicesOnServer2016wDE
{
param(
[String]$ComputerName = "localhost",
[ValidateSet('ShouldBeDisabledOnly','ShouldBeDisabledAndDefaultOnly','OKToDisable','OKToDisablePrinter','OKToDisableDC')]
[String]$Level = 'OKToDisable'
)
CookieContainer cookies = new CookieContainer();
HttpClientHandler handler = new HttpClientHandler();
handler.CookieContainer = cookies;
HttpClient client = new HttpClient(handler);
HttpResponseMessage response = client.GetAsync("http://google.com").Result;
Uri uri = new Uri("http://google.com");
IEnumerable<Cookie> responseCookies = cookies.GetCookies(uri).Cast<Cookie>();
foreach (Cookie cookie in responseCookies)
@stephenpatten
stephenpatten / gist:b7859c41e00f9babb24a8ff1a053483c
Created November 16, 2017 14:31
Logging to Seq is done async
class Program
{
static void Main(string[] args)
{
//Logging to Seq isn't free overall - the app needs to construct LogEvents, capture properties, serialize JSON and (in batches) send HTTP requests to get events from the app into Seq. It's still very fast, but if you create enough events or serialize enough data then you'll see a corresponding consumption of resources.
//The work is split between the application thread and a background thread, though, so apart from capturing of the log data, which happens during the call to Log.Information()(or error, etc.), most of this work happens in the background.
//The code responsible for this actually lives in https://github.com/serilog/serilog-sinks-periodicbatching, and is shared by the Seq sink and many others.
@stephenpatten
stephenpatten / Http.cs
Created October 23, 2017 01:25 — forked from NickCraver/Http.cs
HttpClient Ideas
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;