diff --git a/README.md b/README.md index 666a953..d291a49 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Serilog.Formatting.Compact [![Build status](https://ci.appveyor.com/api/projects/status/ch5il2airviylofn?svg=true)](https://ci.appveyor.com/project/serilog/serilog-formatting-compact) [![NuGet](https://img.shields.io/nuget/vpre/Serilog.Formatting.Compact.svg)](https://nuget.org/packages/Serilog.Formatting.Compact) +# Serilog.Formatting.Compact [![Build status](https://ci.appveyor.com/api/projects/status/ch5il2airviylofn?svg=true)](https://ci.appveyor.com/project/serilog/serilog-formatting-compact) [![NuGet](https://img.shields.io/nuget/v/Serilog.Formatting.Compact.svg)](https://nuget.org/packages/Serilog.Formatting.Compact) A simple, compact JSON-based event format for Serilog. `CompactJsonFormatter` significantly reduces the byte count of small log events when compared with Serilog's default `JsonFormatter`, while remaining human-readable. It achieves this through shorter built-in property names, a leaner format, and by excluding redundant information. @@ -15,16 +15,44 @@ A simple `Hello, {User}` event. Install from [NuGet](https://nuget.org/packages/Serilog.Formatting.Compact): ```powershell -Install-Package Serilog.Formatting.Compact -Pre +Install-Package Serilog.Formatting.Compact ``` -The formatter is used in conjunction with sinks that accept `ITextFormatter`. For example, the [rolling file](https://github.com/serilog/serilog-sinks-rollingfile) sink: +The formatter is used in conjunction with sinks that accept `ITextFormatter`. For example, the [file](https://github.com/serilog/serilog-sinks-file) sink: ```csharp Log.Logger = new LoggerConfiguration() - .WriteTo.Sink(new RollingFileSink("./logs/myapp.txt", new CompactJsonFormatter(), null, null)) + .WriteTo.File(new CompactJsonFormatter(), "./logs/myapp.json") .CreateLogger(); ``` +#### XML `` configuration +To specify the formatter in XML `` provide its assembly-qualified type name: + +```xml + + + + +``` +#### JSON `appsettings.json` configuration +To specify formatter in json `appsettings.json` provide its assembly-qualified type name: + +```json +{ + "Serilog": { + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "./logs/myapp.json", + "formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact" + } + } + ] + } +} +``` ### Rendered events @@ -58,13 +86,13 @@ The format defines a handful of reified properties that have special meaning: | `@l` | Level | An implementation-specific level identifier (string or number) | Absence implies "informational" | | `@x` | Exception | A language-dependent error representation potentially including backtrace | | | `@i` | Event id | An implementation specific event id (string or number) | | -| `@r` | Renderings | If `@mt` includes properties with programming-language-specific formatting, an array of pre-rendered values for each such property | | +| `@r` | Renderings | If `@mt` includes tokens with programming-language-specific formatting, an array of pre-rendered values for each such token | May be omitted; if present, the count of renderings must match the count of formatted tokens exactly | The `@` sigil may be escaped at the start of a user property name by doubling, e.g. `@@name` denotes a property called `@name`. ##### Batch format -When events are batched into a single payload, a newline-delimited stream of JSON documents is required. Either `\n` or `\r\n` delimiters may be used. +When events are batched into a single payload, a newline-delimited stream of JSON documents is required. Either `\n` or `\r\n` delimiters may be used. Batches of newline-separated compact JSON events can use the (unofficial) MIME type `application/vnd.serilog.clef`. ##### Versioning @@ -110,7 +138,16 @@ See `test/Serilog.Formatting.Compact.Tests/FormattingBenchmarks.cs`. | Formatter | Median | StdDev | Scaled | |:------------------------------ |----------: |---------: |------: | -| `JsonFormatter` | 11.2775 us | 0.0682 us | 1.00 | -| `CompactJsonFormatter` | 6.0315 us | 0.0429 us | 0.53 | -| `RenderedJsonFormatter` | 13.7585 us | 0.1194 us | 1.22 | -| `RenderedCompactJsonFormatter` | 7.0680 us | 0.0605 us | 0.63 | +| `JsonFormatter` | 11.2775 µs | 0.0682 µs | 1.00 | +| `CompactJsonFormatter` | 6.0315 µs | 0.0429 µs | 0.53 | +| `RenderedJsonFormatter` | 13.7585 µs | 0.1194 µs | 1.22 | +| `RenderedCompactJsonFormatter` | 7.0680 µs | 0.0605 µs | 0.63 | + +### Tools + +Several tools are available for working with the CLEF format. + + * **[`clef-tool`](https://github.com/datalust/clef-tool)** - a CLI application for processing CLEF files + * **[Compact Log Format Viewer](https://github.com/warrenbuckley/Compact-Log-Format-Viewer)** - a cross-platform viewer for CLEF JSON files + * **[_Serilog.Formatting.Compact.Reader_](https://github.com/serilog/serilog-formatting-compact-reader)** - convert CLEF JSON documents back into Serilog `LogEvent`s + diff --git a/Setup.ps1 b/Setup.ps1 new file mode 100644 index 0000000..e47544f --- /dev/null +++ b/Setup.ps1 @@ -0,0 +1,10 @@ +$ErrorActionPreference = "Stop" + +$RequiredDotnetVersion = $(cat ./global.json | convertfrom-json).sdk.version + +mkdir "./build" +Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./build/installcli.ps1" +& ./build/installcli.ps1 -InstallDir "$pwd/.dotnetcli" -NoPath -Version $RequiredDotnetVersion +if ($LASTEXITCODE) { exit 1 } + +$env:Path = "$pwd/.dotnetcli;$env:Path" \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 19d0d28..699d563 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,13 +1,9 @@ version: '{build}' skip_tags: true -image: Visual Studio 2015 +image: Visual Studio 2019 configuration: Release install: - - ps: mkdir -Force ".\build\" | Out-Null - - ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1" - - ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli" - - ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0-preview2-003121' - - ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path" + - ps: ./Setup.ps1 build_script: - ps: ./Build.ps1 test: off @@ -16,7 +12,7 @@ artifacts: deploy: - provider: NuGet api_key: - secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x + secure: ptRAVPZZO/hlZUv5e/yLnHF7aAh8tQmBfvLt64Qrvhoe7I/mbbPNI6RYm92g5EzG skip_symbols: true on: branch: /^(master|dev)$/ diff --git a/global.json b/global.json index a2b2a41..2223a05 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,5 @@ { - "projects": [ "src", "test" ], "sdk": { - "version": "1.0.0-preview2-003121" + "version": "3.0.100" } -} +} \ No newline at end of file diff --git a/serilog-formatting-compact.sln b/serilog-formatting-compact.sln index ead6d29..c0f7b86 100644 --- a/serilog-formatting-compact.sln +++ b/serilog-formatting-compact.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.26114.2 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}" EndProject @@ -10,16 +10,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5 appveyor.yml = appveyor.yml Build.ps1 = Build.ps1 CHANGES.md = CHANGES.md - global.json = global.json README.md = README.md assets\Serilog.snk = assets\Serilog.snk EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{67B1C971-75EE-4ABE-B184-66AAC8D9D572}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Formatting.Compact", "src\Serilog.Formatting.Compact\Serilog.Formatting.Compact.xproj", "{D8A74F4C-981B-41F1-B807-FE08DFCC06D4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Formatting.Compact", "src\Serilog.Formatting.Compact\Serilog.Formatting.Compact.csproj", "{E0BB862A-8B2C-46B5-9C90-B2F94C32EAB3}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Formatting.Compact.Tests", "test\Serilog.Formatting.Compact.Tests\Serilog.Formatting.Compact.Tests.xproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Formatting.Compact.Tests", "test\Serilog.Formatting.Compact.Tests\Serilog.Formatting.Compact.Tests.csproj", "{BAEECC42-EC0C-4955-8AA1-BD3F4F0F4AAD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,20 +26,20 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D8A74F4C-981B-41F1-B807-FE08DFCC06D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D8A74F4C-981B-41F1-B807-FE08DFCC06D4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D8A74F4C-981B-41F1-B807-FE08DFCC06D4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D8A74F4C-981B-41F1-B807-FE08DFCC06D4}.Release|Any CPU.Build.0 = Release|Any CPU - {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.Build.0 = Release|Any CPU + {E0BB862A-8B2C-46B5-9C90-B2F94C32EAB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0BB862A-8B2C-46B5-9C90-B2F94C32EAB3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0BB862A-8B2C-46B5-9C90-B2F94C32EAB3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0BB862A-8B2C-46B5-9C90-B2F94C32EAB3}.Release|Any CPU.Build.0 = Release|Any CPU + {BAEECC42-EC0C-4955-8AA1-BD3F4F0F4AAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BAEECC42-EC0C-4955-8AA1-BD3F4F0F4AAD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BAEECC42-EC0C-4955-8AA1-BD3F4F0F4AAD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BAEECC42-EC0C-4955-8AA1-BD3F4F0F4AAD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {D8A74F4C-981B-41F1-B807-FE08DFCC06D4} = {037440DE-440B-4129-9F7A-09B42D00397E} - {3C2D8E01-5580-426A-BDD9-EC59CD98E618} = {67B1C971-75EE-4ABE-B184-66AAC8D9D572} + {E0BB862A-8B2C-46B5-9C90-B2F94C32EAB3} = {037440DE-440B-4129-9F7A-09B42D00397E} + {BAEECC42-EC0C-4955-8AA1-BD3F4F0F4AAD} = {67B1C971-75EE-4ABE-B184-66AAC8D9D572} EndGlobalSection EndGlobal diff --git a/src/Serilog.Formatting.Compact/Properties/AssemblyInfo.cs b/src/Serilog.Formatting.Compact/Properties/AssemblyInfo.cs index 38b9efd..72c1391 100644 --- a/src/Serilog.Formatting.Compact/Properties/AssemblyInfo.cs +++ b/src/Serilog.Formatting.Compact/Properties/AssemblyInfo.cs @@ -1,9 +1,5 @@ -using System.Reflection; -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; -[assembly: AssemblyTitle("Serilog.Formatting.Compact")] -[assembly: AssemblyDescription("A simple, compact JSON-based event format for Serilog.")] -[assembly: AssemblyCopyright("Copyright © Serilog Contributors 2013-2016")] [assembly: InternalsVisibleTo("Serilog.Formatting.Compact.Tests, PublicKey=" + "0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + "6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + diff --git a/src/Serilog.Formatting.Compact/Serilog.Formatting.Compact.csproj b/src/Serilog.Formatting.Compact/Serilog.Formatting.Compact.csproj new file mode 100644 index 0000000..0d477cd --- /dev/null +++ b/src/Serilog.Formatting.Compact/Serilog.Formatting.Compact.csproj @@ -0,0 +1,30 @@ + + + + A simple, compact JSON-based event format for Serilog. + 1.1.0 + Serilog Contributors + net452;netstandard1.1;netstandard2.0 + true + true + Serilog.Formatting.Compact + ../../assets/Serilog.snk + true + true + Serilog.Formatting.Compact + serilog;json + http://serilog.net/images/serilog-extension-nuget.png + https://github.com/serilog/serilog-formatting-compact + Apache-2.0 + + + + + + + + + + + + diff --git a/src/Serilog.Formatting.Compact/Serilog.Formatting.Compact.xproj b/src/Serilog.Formatting.Compact/Serilog.Formatting.Compact.xproj deleted file mode 100644 index 8b1b04f..0000000 --- a/src/Serilog.Formatting.Compact/Serilog.Formatting.Compact.xproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - d8a74f4c-981b-41f1-b807-fe08dfcc06d4 - Serilog - .\obj - .\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/src/Serilog.Formatting.Compact/project.json b/src/Serilog.Formatting.Compact/project.json deleted file mode 100644 index d24eed9..0000000 --- a/src/Serilog.Formatting.Compact/project.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "version": "1.0.0-*", - "description": "A simple, compact JSON-based event format for Serilog.", - "authors": [ "Serilog Contributors" ], - "packOptions": { - "tags": [ "serilog", "json" ], - "projectUrl": "https://github.com/nblumhardt/serilog-formatters-compact", - "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", - "iconUrl": "http://serilog.net/images/serilog-community-nuget.png" - }, - "dependencies": { - "Serilog": "2.0.0" - }, - "buildOptions": { - "keyFile": "../../assets/Serilog.snk", - "xmlDoc": true, - "warningsAsErrors": true - }, - "frameworks": { - "net4.5": {}, - "netstandard1.1": {} - } -} diff --git a/test/Serilog.Formatting.Compact.Tests/Serilog.Formatting.Compact.Tests.csproj b/test/Serilog.Formatting.Compact.Tests/Serilog.Formatting.Compact.Tests.csproj new file mode 100644 index 0000000..594962b --- /dev/null +++ b/test/Serilog.Formatting.Compact.Tests/Serilog.Formatting.Compact.Tests.csproj @@ -0,0 +1,30 @@ + + + + net452;netcoreapp2.1 + Serilog.Formatting.Compact.Tests + ../../assets/Serilog.snk + true + true + false + true + + + + + + + + + + + + + + + + + + + + diff --git a/test/Serilog.Formatting.Compact.Tests/Serilog.Formatting.Compact.Tests.xproj b/test/Serilog.Formatting.Compact.Tests/Serilog.Formatting.Compact.Tests.xproj deleted file mode 100644 index 858c7cc..0000000 --- a/test/Serilog.Formatting.Compact.Tests/Serilog.Formatting.Compact.Tests.xproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 3c2d8e01-5580-426a-bdd9-ec59cd98e618 - Serilog.Formatting.Compact.Tests - .\obj - .\bin\ - - - 2.0 - - - - - - \ No newline at end of file diff --git a/test/Serilog.Formatting.Compact.Tests/project.json b/test/Serilog.Formatting.Compact.Tests/project.json deleted file mode 100644 index 9a50248..0000000 --- a/test/Serilog.Formatting.Compact.Tests/project.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "testRunner": "xunit", - "dependencies": { - "Serilog.Formatting.Compact": { "target": "project" }, - "xunit": "2.1.0", - "dotnet-test-xunit": "1.0.0-rc2-build10025", - "Newtonsoft.Json": "8.0.3", - "BenchmarkDotNet": "0.9.7-beta" - }, - "buildOptions": { - "keyFile": "../../assets/Serilog.snk" - }, - "frameworks": { - "net4.5.2": {}, - "netcoreapp1.0": { - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - } - }, - "imports": [ - "dnxcore50", - "portable-net45+win8" - ] - } - } -}