nssm.exe install SERVICE_NAME "C:\path\to\exe\or\bat\file.ext" "argument1 argument2"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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' | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git config core.editor "'C:\Program Files (x86)\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
<!- .... ->
<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" />
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Initialize the logger in the constructor: | |
| class SomethingAbstract | |
| { | |
| protected ILogger Log { get; } | |
| protected SomethingAbstract() | |
| { | |
| Log = Log.ForContext(GetType()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Retry http with a back off on failure | |
| await Policy.Handle<HttpRequestException>().WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))) | |
| .ExecuteAsync(async () => | |
| { | |
| var result = await httpClient.GetAsync("api/CallToServer/" + varibleToSendToServer, cancellationToken); | |
| if (result.IsSuccessStatusCode) | |
| { | |
| returnValue = await result.Content.ReadAsAsync<List<Results>>(token); | |
| } |