├── .config └── dotnet-tools.json ├── .editorconfig ├── examples ├── CSharpExample │ ├── appsettings.json │ ├── CSharpExample.csproj │ └── Program.cs └── FSharpExample │ ├── appsettings.json │ ├── FSharpExample.fsproj │ └── Program.fs ├── .github └── workflows │ ├── build.yml │ └── deploy.yml ├── src └── Serilog.Sinks.SpectreConsole │ ├── SpectreConsole.fs │ ├── SpectreConsoleSink.fs │ ├── Serilog.Sinks.SpectreConsole.fsproj │ ├── LevelOutputFormat.fs │ └── SpectreRenderer.fs ├── README.md ├── Serilog.Sinks.SpectreConsole.sln ├── .gitignore └── LICENSE /.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "cake.tool": { 6 | "version": "0.37.0", 7 | "commands": [ 8 | "dotnet-cake" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: 2 | http://EditorConfig.org 3 | 4 | # top-most EditorConfig file 5 | root = true 6 | 7 | # Default settings: 8 | # A newline ending every file 9 | # Use 4 spaces as indentation 10 | [*] 11 | charset = utf-8 12 | insert_final_newline = true 13 | indent_style = space 14 | indent_size = 4 15 | trim_trailing_whitespace = true 16 | -------------------------------------------------------------------------------- /examples/CSharpExample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Serilog": { 3 | "MinimumLevel": "Verbose", 4 | "Using": [ "Serilog.Sinks.SpectreConsole" ], 5 | "WriteTo": [ 6 | { 7 | "Name": "SpectreConsole", 8 | "Args": { 9 | "outputTemplate": "{Timestamp:HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}", 10 | "minLevel": "Verbose" 11 | } 12 | } 13 | ] 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/FSharpExample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Serilog": { 3 | "MinimumLevel": "Verbose", 4 | "Using": [ "Serilog.Sinks.SpectreConsole" ], 5 | "WriteTo": [ 6 | { 7 | "Name": "SpectreConsole", 8 | "Args": { 9 | "outputTemplate": "{Timestamp:HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}", 10 | "minLevel": "Verbose" 11 | } 12 | } 13 | ] 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [ "dev" ] 6 | pull_request: 7 | branches: [ "dev" ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Setup .NET 17 | uses: actions/setup-dotnet@v2 18 | with: 19 | dotnet-version: 6.x.x 20 | - name: Restore dependencies 21 | run: dotnet restore 22 | - name: Build 23 | run: dotnet build --no-restore 24 | - name: Test 25 | run: dotnet test --no-build --verbosity normal 26 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: deploy 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | 7 | jobs: 8 | deploy: 9 | environment: PROD 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Setup .NET 15 | uses: actions/setup-dotnet@v2 16 | with: 17 | dotnet-version: 6.x.x 18 | - name: Restore dependencies 19 | run: dotnet restore 20 | - name: Pack 21 | run: dotnet pack src/Serilog.Sinks.SpectreConsole/Serilog.Sinks.SpectreConsole.fsproj -c Release -o artifacts --include-source 22 | - name: Publish 23 | run: dotnet nuget push artifacts/**.nupkg -s https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_TOKEN }} 24 | -------------------------------------------------------------------------------- /examples/CSharpExample/CSharpExample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | PreserveNewest 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/FSharpExample/FSharpExample.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/Serilog.Sinks.SpectreConsole/SpectreConsole.fs: -------------------------------------------------------------------------------- 1 | module internal SpectreConsole 2 | 3 | open Spectre.Console 4 | open Spectre.Console.Rendering 5 | 6 | let empty: IRenderable = 7 | Text.Empty 8 | 9 | let text (text): IRenderable = 10 | Text text 11 | 12 | let markup (text): IRenderable = 13 | Markup text 14 | 15 | let error (ex: exn): IRenderable = 16 | ex.GetRenderable() 17 | 18 | let newLine: IRenderable = 19 | Text.NewLine 20 | 21 | let escapeMarkup (text) = 22 | Markup.Escape text 23 | 24 | let highlightProp (text) = 25 | $"[lime]{text}[/]" 26 | 27 | let highlightMuted (text) = 28 | $"[grey]{text}[/]" 29 | 30 | let highlightVerbose (text) = 31 | highlightMuted(text) 32 | 33 | let highlightDebug (text) = 34 | $"[silver]{text}[/]" 35 | 36 | let highlightInfo (text) = 37 | $"[deepskyblue1]{text}[/]" 38 | 39 | let highlightWarning (text) = 40 | $"[yellow]{text}[/]" 41 | 42 | let highlightError (text) = 43 | $"[red]{text}[/]" 44 | 45 | let highlightFatal (text) = 46 | $"[maroon]{text}[/]" 47 | -------------------------------------------------------------------------------- /src/Serilog.Sinks.SpectreConsole/SpectreConsoleSink.fs: -------------------------------------------------------------------------------- 1 | namespace Serilog.Sinks.SpectreConsole 2 | 3 | open System.Runtime.CompilerServices 4 | open System.Runtime.InteropServices 5 | 6 | open Serilog.Configuration 7 | open Serilog.Core 8 | open Serilog.Events 9 | open Serilog.Parsing 10 | open Serilog.Sinks.SpectreConsole.SpectreRenderer 11 | open Spectre.Console 12 | 13 | module internal LogEvent = 14 | 15 | [] 16 | let DefaultConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}" 17 | 18 | type SpectreConsoleSink (outputTemplate: string) = 19 | 20 | let template = MessageTemplateParser().Parse(outputTemplate) 21 | let _renderers = template.Tokens |> Seq.map(SpectreRenderer.createRenderer template) |> Array.ofSeq 22 | 23 | interface ILogEventSink with 24 | 25 | member _.Emit(logEvent: LogEvent) = 26 | _renderers 27 | |> Seq.collect(fun renderer -> renderer logEvent) 28 | |> RenderableCollection 29 | |> AnsiConsole.Write 30 | 31 | [] 32 | type SpectreConsoleSinkExtensions() = 33 | 34 | [] 35 | static member SpectreConsole (loggerConfiguration: LoggerSinkConfiguration, 36 | [] outputTemplate: string, 37 | [] minLevel: LogEventLevel) = 38 | 39 | let sink = SpectreConsoleSink(outputTemplate) 40 | loggerConfiguration.Sink(sink, minLevel) 41 | -------------------------------------------------------------------------------- /src/Serilog.Sinks.SpectreConsole/Serilog.Sinks.SpectreConsole.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0 4 | Yaroshvitaliy,Anton Moldovan 5 | NBomber 6 | 0.3.3 7 | PragmaticFlow@2022 8 | true 9 | snupkg 10 | LICENSE 11 | https://github.com/PragmaticFlow/Serilog.Sinks.SpectreConsole 12 | https://github.com/PragmaticFlow/Serilog.Sinks.SpectreConsole 13 | serilog, spectre.console 14 | false 15 | true 16 | A Serilog sink that writes log events to console using Spectre.Console. 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /examples/CSharpExample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Microsoft.Extensions.Configuration; 4 | using Serilog; 5 | using Serilog.Events; 6 | using Serilog.Sinks.SpectreConsole; 7 | 8 | namespace CSharpExample 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | Log.Logger = new LoggerConfiguration() 15 | .WriteTo.SpectreConsole("{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}", minLevel: LogEventLevel.Verbose) 16 | .MinimumLevel.Verbose() 17 | .CreateLogger(); 18 | 19 | // or for configuration via appsettings.json 20 | 21 | //var configuration = new ConfigurationBuilder() 22 | // .SetBasePath(Directory.GetCurrentDirectory()) 23 | // .AddJsonFile("appsettings.json") 24 | // .Build(); 25 | 26 | //Log.Logger = new LoggerConfiguration() 27 | // .ReadFrom.Configuration(configuration) 28 | // .CreateLogger(); 29 | 30 | Log.Information("symbol {"); 31 | 32 | Log.Verbose("Verbose level example with {0}", "parameter"); 33 | Log.Debug("Debug level example with {0}", "parameter"); 34 | Log.Information("Information level example with {0}", "parameter"); 35 | Log.Warning("Warning level example with {0}", "parameter"); 36 | 37 | try 38 | { 39 | throw new Exception("Message"); 40 | } 41 | catch(Exception ex) 42 | { 43 | Log.Error(ex, "Error level example with {0}", "parameter"); 44 | } 45 | 46 | Log.Fatal("Fatal level example with {0}", "parameter"); 47 | 48 | Console.ReadKey(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/FSharpExample/Program.fs: -------------------------------------------------------------------------------- 1 | open System 2 | open System.IO 3 | 4 | open System.Threading.Tasks 5 | open Microsoft.Extensions.Configuration 6 | 7 | open Serilog 8 | open Serilog.Events 9 | open Serilog.Sinks.SpectreConsole 10 | open Spectre.Console 11 | 12 | type User = { 13 | Name: string 14 | } 15 | 16 | [] 17 | let main argv = 18 | 19 | Log.Logger <- 20 | LoggerConfiguration() 21 | .WriteTo.SpectreConsole("{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}", minLevel = LogEventLevel.Verbose) 22 | .MinimumLevel.Verbose() 23 | .Enrich.WithProperty("SessionId", "My Session 1111 ID") 24 | .CreateLogger() 25 | 26 | // or for configuration via appsettings.json 27 | 28 | //let configuration = 29 | // ConfigurationBuilder() 30 | // .SetBasePath(Directory.GetCurrentDirectory()) 31 | // .AddJsonFile("appsettings.json") 32 | // .Build() 33 | 34 | //Log.Logger <- 35 | // LoggerConfiguration() 36 | // .ReadFrom.Configuration(configuration) 37 | // .CreateLogger() 38 | 39 | let status = AnsiConsole.Status() 40 | status.Start("my status", fun ctx -> 41 | let user = { Name = "test_user" } 42 | Log.Information($"%A{user}") 43 | Log.Information("symbol {") 44 | 45 | Log.Verbose("Verbose level example with {0}", "parameter") 46 | Log.Debug("Debug level example with {0}", "parameter") 47 | Log.Information("Information level example with {0}", "parameter") 48 | Log.Warning("Warning level example with {0}", "parameter") 49 | 50 | Task.Delay(5000).Wait() 51 | ) 52 | 53 | // let user = { Name = "test_user" } 54 | // Log.Information($"%A{user}") 55 | // Log.Information("symbol {") 56 | // 57 | // Log.Verbose("Verbose level example with {0}", "parameter") 58 | // Log.Debug("Debug level example with {0}", "parameter") 59 | // Log.Information("Information level example with {0}", "parameter") 60 | // Log.Warning("Warning level example with {0}", "parameter") 61 | 62 | try 63 | raise (Exception "Message") 64 | with 65 | | ex -> Log.Error(ex, "Error level example with {0}", "parameter") 66 | 67 | Log.Fatal("Fatal level example with {0}", "parameter") 68 | 69 | Console.ReadKey() |> ignore 70 | 71 | 0 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Serilog.Sinks.SpectreConsole 2 | 3 | [![build](https://github.com/PragmaticFlow/Serilog.Sinks.SpectreConsole/actions/workflows/build.yml/badge.svg)](https://github.com/PragmaticFlow/Serilog.Sinks.SpectreConsole/actions/workflows/build.yml) 4 | [![NuGet](https://img.shields.io/nuget/v/Serilog.Sinks.SpectreConsole.svg)](https://www.nuget.org/packages/Serilog.Sinks.SpectreConsole/) 5 | [![Gitter](https://badges.gitter.im/nbomber/community.svg)](https://gitter.im/nbomber/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 6 | 7 | A Serilog sink that writes log events to console using [Spectre.Console](https://github.com/spectresystems/spectre.console). \ 8 | Output is plain text. \ 9 | The sink is written in F#. 10 | 11 | ## Getting started 12 | The sink is available as a NuGet package. \ 13 | You can install it using the following command: 14 | 15 | `Install-Package Serilog.Sinks.SpectreConsole` 16 | 17 | To enable the sink, use .SpectreConsole() extension method. 18 | 19 | ```csharp 20 | Log.Logger = new LoggerConfiguration() 21 | .WriteTo.SpectreConsole("{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}", minLevel: LogEventLevel.Information) 22 | .MinimumLevel.Verbose() 23 | .CreateLogger(); 24 | 25 | Log.Information("Information level example with {0}", "parameter"); 26 | ``` 27 | 28 | For more information, take a look at examples. 29 | 30 | ## Configuration via `appsettings.json` 31 | To configure the sink via 'appsettings.json' configuration, you have to install NuGet packages: 32 | 33 | `Install-Package Microsoft.Extensions.Configuration.Json` 34 | `Install-Package Serilog.Settings.Configuration` 35 | 36 | Then use `ReadFrom.Configuration()` method. 37 | 38 | ```csharp 39 | var configuration = new ConfigurationBuilder() 40 | .SetBasePath(Directory.GetCurrentDirectory()) 41 | .AddJsonFile("appsettings.json") 42 | .Build(); 43 | 44 | Log.Logger = new LoggerConfiguration() 45 | .ReadFrom.Configuration() 46 | .CreateLogger(); 47 | ``` 48 | 49 | In `appsettings.json` configuration file, write the following section: 50 | 51 | ```json 52 | "Serilog": { 53 | "WriteTo": [ 54 | { 55 | "Name": "SpectreConsole", 56 | "Args": { 57 | "outputTemplate": "{Timestamp:HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}", 58 | "minLevel": "Verbose" 59 | } 60 | } 61 | ] 62 | } 63 | ``` 64 | -------------------------------------------------------------------------------- /Serilog.Sinks.SpectreConsole.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Serilog.Sinks.SpectreConsole", "src\Serilog.Sinks.SpectreConsole\Serilog.Sinks.SpectreConsole.fsproj", "{C4490468-AD7D-4ABE-821E-6480413DEEC5}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{2CB912AE-0C99-4EF0-98A6-2CF635FE4913}" 9 | EndProject 10 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpExample", "examples\FSharpExample\FSharpExample.fsproj", "{99DDBB41-2367-4256-BDCE-6C1C33A6B2EA}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpExample", "examples\CSharpExample\CSharpExample.csproj", "{3955F9F4-795D-4FD4-9C98-69B8988D027B}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EA677E9C-F1F3-404E-8A92-609EFC4A31B4}" 15 | ProjectSection(SolutionItems) = preProject 16 | README.md = README.md 17 | EndProjectSection 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Any CPU = Debug|Any CPU 22 | Release|Any CPU = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {C4490468-AD7D-4ABE-821E-6480413DEEC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {C4490468-AD7D-4ABE-821E-6480413DEEC5}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {C4490468-AD7D-4ABE-821E-6480413DEEC5}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {C4490468-AD7D-4ABE-821E-6480413DEEC5}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {99DDBB41-2367-4256-BDCE-6C1C33A6B2EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {99DDBB41-2367-4256-BDCE-6C1C33A6B2EA}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {99DDBB41-2367-4256-BDCE-6C1C33A6B2EA}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {99DDBB41-2367-4256-BDCE-6C1C33A6B2EA}.Release|Any CPU.Build.0 = Release|Any CPU 33 | {3955F9F4-795D-4FD4-9C98-69B8988D027B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {3955F9F4-795D-4FD4-9C98-69B8988D027B}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {3955F9F4-795D-4FD4-9C98-69B8988D027B}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {3955F9F4-795D-4FD4-9C98-69B8988D027B}.Release|Any CPU.Build.0 = Release|Any CPU 37 | EndGlobalSection 38 | GlobalSection(SolutionProperties) = preSolution 39 | HideSolutionNode = FALSE 40 | EndGlobalSection 41 | GlobalSection(NestedProjects) = preSolution 42 | {99DDBB41-2367-4256-BDCE-6C1C33A6B2EA} = {2CB912AE-0C99-4EF0-98A6-2CF635FE4913} 43 | {3955F9F4-795D-4FD4-9C98-69B8988D027B} = {2CB912AE-0C99-4EF0-98A6-2CF635FE4913} 44 | EndGlobalSection 45 | GlobalSection(ExtensibilityGlobals) = postSolution 46 | SolutionGuid = {872581FA-2E2F-4FFC-86DE-2A6DF906848C} 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /src/Serilog.Sinks.SpectreConsole/LevelOutputFormat.fs: -------------------------------------------------------------------------------- 1 | module internal LevelOutputFormat 2 | 3 | open Serilog.Events 4 | open System 5 | 6 | let private lowerCaseFormat = "w" 7 | let private titleCaseFormat = "t" 8 | let private upperCaseFormat = "u" 9 | 10 | let private verboseLevelMonikers = 11 | [ lowerCaseFormat, ["v"; "vb"; "vrb"; "verb"; "verbo"; "verbos"; "verbose"] 12 | titleCaseFormat, ["V"; "Vb"; "Vrb"; "Verb"; "Verbo"; "Verbos"; "Verbose"] 13 | upperCaseFormat, ["V"; "VB"; "VRB"; "VERB"; "VERBO"; "VERBOS"; "VERBOSE"] ] 14 | |> Map.ofSeq 15 | 16 | let private debugLevelMonikers = 17 | [ lowerCaseFormat, ["d"; "de"; "dbg"; "dbug"; "debug"] 18 | titleCaseFormat, ["D"; "De"; "Dbg"; "Dbug"; "Debug"] 19 | upperCaseFormat, ["D"; "DE"; "DBG"; "DBUG"; "DEBUG"] ] 20 | |> Map.ofSeq 21 | 22 | let private informationLevelMonikers = 23 | [ lowerCaseFormat, ["i"; "in"; "inf"; "info"; "infor"; "inform"; "informa"; "informat"; "informati"; "informatio"; "information"] 24 | titleCaseFormat, ["I"; "In"; "Inf"; "Info"; "Infor"; "Inform"; "Informa"; "Informat"; "Informati"; "Informatio"; "Information"] 25 | upperCaseFormat, ["I"; "IN"; "INF"; "INFO"; "INFOR"; "INFORM"; "INFORMA"; "INFORMAT"; "INFORMATI"; "INFORMATIO"; "INFORMATION"] ] 26 | |> Map.ofSeq 27 | 28 | let private warningLevelMonikers = 29 | [ lowerCaseFormat, ["w"; "wn"; "wrn"; "warn"; "warni"; "warnin"; "warning"] 30 | titleCaseFormat, ["W"; "Wn"; "Wrn"; "Warn"; "Warni"; "Warnin"; "Warning"] 31 | upperCaseFormat, ["W"; "WN"; "WRN"; "WARN"; "WARNI"; "WARNIN"; "WARNING"] ] 32 | |> Map.ofSeq 33 | 34 | let private errorLevelMonikers = 35 | [ lowerCaseFormat, ["e"; "er"; "err"; "eror"; "error"] 36 | titleCaseFormat, ["E"; "Er"; "Err"; "Eror"; "Error"] 37 | upperCaseFormat, ["E"; "ER"; "ERR"; "EROR"; "ERROR"] ] 38 | |> Map.ofSeq 39 | 40 | let private fatalLevelMonikers = 41 | [ lowerCaseFormat, ["f"; "fa"; "ftl"; "fatl"; "fatal"] 42 | titleCaseFormat, ["F"; "Fa"; "Ftl"; "Fatl"; "Fatal"] 43 | upperCaseFormat, ["F"; "FA"; "FTL"; "FATL"; "FATAL"] ] 44 | |> Map.ofSeq 45 | 46 | let private levelMonikers = 47 | [ LogEventLevel.Verbose, verboseLevelMonikers 48 | LogEventLevel.Debug, debugLevelMonikers 49 | LogEventLevel.Information, informationLevelMonikers 50 | LogEventLevel.Warning, warningLevelMonikers 51 | LogEventLevel.Error, errorLevelMonikers 52 | LogEventLevel.Fatal, fatalLevelMonikers ] 53 | |> Map.ofSeq 54 | 55 | let private getCaseFormat (format: string, defaultValue: string) = 56 | if (isNull format) || (format.Length <> 2 && format.Length <> 3) then 57 | defaultValue 58 | else 59 | let caseFormat = format.[0].ToString() 60 | if caseFormat = lowerCaseFormat || caseFormat = titleCaseFormat || caseFormat = upperCaseFormat then 61 | caseFormat 62 | else 63 | defaultValue 64 | 65 | let private getMonikerWidth (format: string, defaultValue: int) = 66 | if isNull format then 67 | defaultValue 68 | else if format.Length = 2 || format.Length = 3 then 69 | let (parsed, width) = Int32.TryParse(format.Substring(1)) 70 | if parsed && width > 0 then 71 | width 72 | else 73 | defaultValue 74 | else 75 | defaultValue 76 | 77 | let getLevelMoniker (format: string) (level: LogEventLevel) = 78 | if levelMonikers.ContainsKey(level) then 79 | let caseFormat = getCaseFormat(format, titleCaseFormat) 80 | let monikerWidth = getMonikerWidth(format, 3) 81 | let monikers = levelMonikers[level][caseFormat] 82 | let index = Math.Min(monikerWidth, monikers.Length) - 1 83 | let moniker = monikers[index] 84 | moniker 85 | else 86 | level.ToString() 87 | -------------------------------------------------------------------------------- /src/Serilog.Sinks.SpectreConsole/SpectreRenderer.fs: -------------------------------------------------------------------------------- 1 | namespace Serilog.Sinks.SpectreConsole 2 | 3 | open Serilog.Events 4 | open Serilog.Formatting.Display 5 | open Serilog.Parsing 6 | open Spectre.Console.Rendering 7 | 8 | module internal LogEventPropertyValue = 9 | 10 | let toString (token: PropertyToken) (value: LogEventPropertyValue) = 11 | value.ToString(token.Format, null) 12 | 13 | module internal StructureValue = 14 | 15 | let toString (token: PropertyToken) (value: StructureValue) = 16 | value.ToString(token.Format, null) 17 | 18 | module internal MessageTemplate = 19 | 20 | let containsPropName (propName: string) (template: MessageTemplate) = 21 | template.Tokens 22 | |> Seq.exists(fun token -> 23 | (token :? PropertyToken) && (token :?> PropertyToken).PropertyName = propName 24 | ) 25 | 26 | module internal SpectreRenderer = 27 | 28 | type RenderableCollection(items: IRenderable seq) = 29 | 30 | interface IRenderable with 31 | member this.Measure(context, maxWidth) = 32 | Measurement() // not used 33 | 34 | member this.Render(context, maxWidth) = 35 | items 36 | |> Seq.collect(fun x -> x.Render(context, maxWidth)) 37 | 38 | let textRenderer (token: TextToken) (logEvent: LogEvent) = 39 | SpectreConsole.text token.Text 40 | 41 | let propRenderer (token: PropertyToken) (logEvent: LogEvent) = 42 | if logEvent.Properties.ContainsKey(token.PropertyName) then 43 | logEvent.Properties[token.PropertyName] 44 | |> LogEventPropertyValue.toString token 45 | |> SpectreConsole.escapeMarkup 46 | |> SpectreConsole.highlightProp 47 | |> SpectreConsole.markup 48 | else 49 | SpectreConsole.empty 50 | 51 | let messageRenderer (logEvent: LogEvent) = 52 | logEvent.MessageTemplate.Tokens 53 | |> Seq.map(fun token -> 54 | if token :? TextToken then 55 | textRenderer (token :?> TextToken) logEvent 56 | else 57 | propRenderer (token :?> PropertyToken) logEvent 58 | ) 59 | |> Seq.toList 60 | 61 | let timestampRenderer (token: PropertyToken) (logEvent: LogEvent)= 62 | token.Format 63 | |> logEvent.Timestamp.ToString 64 | |> SpectreConsole.text 65 | 66 | let levelRenderer (token: PropertyToken) (logEvent: LogEvent) = 67 | 68 | let levelMoniker = LevelOutputFormat.getLevelMoniker token.Format logEvent.Level 69 | 70 | match logEvent.Level with 71 | | LogEventLevel.Verbose -> levelMoniker |> SpectreConsole.highlightVerbose 72 | | LogEventLevel.Debug -> levelMoniker |> SpectreConsole.highlightDebug 73 | | LogEventLevel.Information -> levelMoniker |> SpectreConsole.highlightInfo 74 | | LogEventLevel.Warning -> levelMoniker |> SpectreConsole.highlightWarning 75 | | LogEventLevel.Error -> levelMoniker |> SpectreConsole.highlightError 76 | | LogEventLevel.Fatal -> levelMoniker |> SpectreConsole.highlightFatal 77 | | _ -> levelMoniker 78 | |> SpectreConsole.markup 79 | 80 | let newLineRenderer (logEvent: LogEvent) = 81 | SpectreConsole.newLine 82 | 83 | let exceptionRenderer (logEvent: LogEvent) = 84 | if isNull logEvent.Exception 85 | then SpectreConsole.empty 86 | else 87 | SpectreConsole.error logEvent.Exception 88 | 89 | let propertiesRenderer (token: PropertyToken) (outputTemplate: MessageTemplate) (logEvent: LogEvent) = 90 | 91 | let shouldBeRendered (propName: string) (logEvent: LogEvent) (outputTemplate: MessageTemplate) = 92 | not (MessageTemplate.containsPropName propName logEvent.MessageTemplate) 93 | && not (MessageTemplate.containsPropName propName outputTemplate) 94 | 95 | logEvent.Properties 96 | |> Seq.filter(fun x -> shouldBeRendered x.Key logEvent outputTemplate) 97 | |> Seq.map(fun x -> LogEventProperty(x.Key, x.Value)) 98 | |> StructureValue 99 | |> StructureValue.toString token 100 | |> SpectreConsole.escapeMarkup 101 | |> SpectreConsole.highlightMuted 102 | |> SpectreConsole.markup 103 | 104 | let eventPropRenderer (token: PropertyToken) (logEvent: LogEvent) = 105 | propRenderer token logEvent 106 | 107 | let createRenderer (outputTemplate: MessageTemplate) (token: MessageTemplateToken) = 108 | match token with 109 | | :? TextToken as t -> textRenderer t >> List.singleton 110 | 111 | | :? PropertyToken as t -> 112 | match t.PropertyName with 113 | | OutputProperties.MessagePropertyName -> messageRenderer 114 | | OutputProperties.TimestampPropertyName -> timestampRenderer t >> List.singleton 115 | | OutputProperties.LevelPropertyName -> levelRenderer t >> List.singleton 116 | | OutputProperties.NewLinePropertyName -> newLineRenderer >> List.singleton 117 | | OutputProperties.ExceptionPropertyName -> exceptionRenderer >> List.singleton 118 | | OutputProperties.PropertiesPropertyName -> propertiesRenderer t outputTemplate >> List.singleton 119 | | _ -> eventPropRenderer t >> List.singleton 120 | 121 | | _ -> failwith "unsupported token" 122 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | .idea/ 352 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------