Skip to content

Commit

Permalink
Add Seq, improve logging; v1.2.0
Browse files Browse the repository at this point in the history
- Add Seq as a logging Sink for Serilog
- Document logging to MS SQL Server and Seq
- Add default rolling text file logging
- Improve logging to be uniformly structured
- Clean up code issues
- Update packages and remove deprecated packages
  • Loading branch information
k7hpn committed Feb 21, 2020
1 parent d5881d0 commit 5db16fc
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 56 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.1.0]
## [1.2.0]
### Added
- Serilog.Sinks.Seq so that logging can happen to Seq
- Configurable rolling file log

### Fixed
- Logging is now uniformly structured
- General code clean-up

## [1.1.0] - 2017-11-21
### Added
- Option to delete source file once uploaded
- Handle multiple files matching a wildcard path
Expand All @@ -19,3 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Ability to compress files before uploading ([ZIP](https://en.wikipedia.org/wiki/Zip_(file_format)) compression)
- Replacement of `{date}` in destination file name with date in `yyyy-MM-dd` format
- Optional ability to send an email notification when a job is complete

[1.2.0]: https://github.com/MCLD/uploader/releases/tag/v1.2.0
[1.1.0]: https://github.com/MCLD/uploader/releases/tag/v1.1.0
[1.0.0]: https://github.com/MCLD/uploader/releases/tag/v1.0.0
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,37 @@ Jobs can optionally be set to send email once they are complete. Email configura
</system.net>
```

# Logging
Console logging is on by default. Additional logging configurations can be set in `Uploader.Console.exe.config`:

## SQL Server
In `<appSettings>` add:

```xml
<add key="serilog:using:MSSqlSever" value="Serilog.Sinks.MSSqlServer"/>
<add key="serilog:write-to:MSSqlServer.restrictedToMinimumLevel" value="Information"/>
<add key="serilog:write-to:MSSqlServer.connectionString" value="[SQL Server connection string]"/>
<add key="serilog:write-to:MSSqlServer.tableName" value="[SQL Server logging table name]"/>
<add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="true"/>
```

## Seq
In `<appSettings>` add:

```xml
<add key="serilog:using:Seq" value="Serilog.Sinks.Seq" />
<add key="serilog:write-to:Seq.serverUrl" value="[Seq logging endpoint]" />
<add key="serilog:write-to:Seq.apiKey" value="[optional API key here]" />
```

# Dependencies
- Newtonsoft.Json
- Serilog
- Serilog.Settings.AppSettings
- Serilog.Sinks.Console
- Serilog.Sinks.Literate
- Serilog.Sinks.PeriodicBatching
- Serilog.Sinks.Seq

# License
Code released under the [MIT License](https://github.com/MCLD/uploader/blob/master/LICENSE).
6 changes: 4 additions & 2 deletions Uploader.Console/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<configSections />
<appSettings>
<add key="serilog:minimum-level" value="Verbose" />
<add key="serilog:using:LiterateConsole" value="Serilog.Sinks.Literate" />
<add key="serilog:write-to:LiterateConsole" />
<add key="serilog:using:File" value="Serilog.Sinks.File" />
<add key="serilog:write-to:File.path" value="logs/log.txt" />
<add key="serilog:write-to:File.rollingInterval" value="Day" />
<add key="serilog:write-to:File.retainedFileCountLimit" value="13" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.net>
Expand Down
19 changes: 8 additions & 11 deletions Uploader.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using Serilog;
using System;
using System.Configuration;
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Serilog;

namespace Uploader.Console
{
class Program
internal static class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
using (var log = new LoggerConfiguration()
.ReadFrom.AppSettings()
Expand All @@ -18,25 +16,24 @@ static void Main(string[] args)
.Enrich.WithProperty("Identifier", Process.GetCurrentProcess().Id)
.CreateLogger())
{
if (args.Count() == 0)
if (args.Length == 0)
{
log.Fatal("Must supply one or more job names to perform upload.");
log.Fatal("Must supply one or more job names to perform upload, see jobs.json.");
throw new ArgumentNullException();
}
else
{
var settings = ConfigurationManager.AppSettings;
foreach (string arg in args)
{
log.Verbose("Processing {arg}...", arg);
var uploader = new Uploader(log, settings);
var uploader = new Uploader(log);
try
{
uploader.Process(arg);
}
catch (Exception ex)
{
log.Fatal(ex, "Fatal exception");
log.Fatal(ex, "Fatal exception: {ErrorMessage}", ex.Message);
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion Uploader.Console/Uploader.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.1.0.%2a</ApplicationVersion>
<ApplicationVersion>1.2.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -48,31 +49,50 @@
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.5.0\lib\net45\Serilog.dll</HintPath>
</Reference>
<Reference Include="Serilog.Formatting.Compact, Version=1.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Formatting.Compact.1.0.0\lib\net45\Serilog.Formatting.Compact.dll</HintPath>
</Reference>
<Reference Include="Serilog.Settings.AppSettings, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Settings.AppSettings.2.1.2\lib\net45\Serilog.Settings.AppSettings.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.Console, Version=3.1.1.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.Console.3.1.1\lib\net45\Serilog.Sinks.Console.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.File, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.File.4.0.0\lib\net45\Serilog.Sinks.File.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.Literate, Version=3.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.Literate.3.0.0\lib\net45\Serilog.Sinks.Literate.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.PeriodicBatching, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.PeriodicBatching.2.1.1\lib\net45\Serilog.Sinks.PeriodicBatching.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.RollingFile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.RollingFile.3.3.0\lib\net45\Serilog.Sinks.RollingFile.dll</HintPath>
</Reference>
<Reference Include="Serilog.Sinks.Seq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.Seq.4.0.0\lib\net45\Serilog.Sinks.Seq.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down
Loading

0 comments on commit 5db16fc

Please sign in to comment.