From 35783c5f257e1a9be36c1bbf660ce73d1f9389b4 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Sun, 21 Jan 2024 10:58:13 +0300 Subject: [PATCH] Update readme with badges + format (#77) --- README.md | 97 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 39bb753..2193a4f 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,28 @@ -# Destructurama.Attributed +# Destructurama.Attributed -[![Build status](https://ci.appveyor.com/api/projects/status/1tutmofqjb9wq627/branch/master?svg=true)](https://ci.appveyor.com/project/Destructurama/attributed) -[![NuGet Status](https://img.shields.io/nuget/v/Destructurama.Attributed.svg)](https://www.nuget.org/packages/Destructurama.Attributed/) +![License](https://img.shields.io/github/license/destructurama/attributed) -This package makes it possible to manipulate how objects are logged to [Serilog](https://serilog.net) using attributes. +[![codecov](https://codecov.io/gh/destructurama/attributed/branch/master/graph/badge.svg?token=0ZRHIUEQM4)](https://codecov.io/gh/destructurama/attributed) +[![Nuget](https://img.shields.io/nuget/dt/Destructurama.Attributed)](https://www.nuget.org/packages/Destructurama.Attributed) +[![Nuget](https://img.shields.io/nuget/v/Destructurama.Attributed)](https://www.nuget.org/packages/Destructurama.Attributed) + +[![GitHub Release Date](https://img.shields.io/github/release-date/destructurama/attributed?label=released)](https://github.com/destructurama/attributed/releases) +[![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/destructurama/attributed/latest?label=new+commits)](https://github.com/destructurama/attributed/commits/master) +![Size](https://img.shields.io/github/repo-size/destructurama/attributed) + +[![GitHub contributors](https://img.shields.io/github/contributors/destructurama/attributed)](https://github.com/destructurama/attributed/graphs/contributors) +![Activity](https://img.shields.io/github/commit-activity/w/destructurama/attributed) +![Activity](https://img.shields.io/github/commit-activity/m/destructurama/attributed) +![Activity](https://img.shields.io/github/commit-activity/y/destructurama/attributed) +[![Run unit tests](https://github.com/destructurama/attributed/actions/workflows/test.yml/badge.svg)](https://github.com/destructurama/attributed/actions/workflows/test.yml) +[![Publish preview to GitHub registry](https://github.com/destructurama/attributed/actions/workflows/publish-preview.yml/badge.svg)](https://github.com/destructurama/attributed/actions/workflows/publish-preview.yml) +[![Publish release to Nuget registry](https://github.com/destructurama/attributed/actions/workflows/publish-release.yml/badge.svg)](https://github.com/destructurama/attributed/actions/workflows/publish-release.yml) +[![CodeQL analysis](https://github.com/destructurama/attributed/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/destructurama/attributed/actions/workflows/codeql-analysis.yml) + +This package makes it possible to manipulate how objects are logged to [Serilog](https://serilog.net) using attributes. -## Enabling the module: +# Installation Install from NuGet: @@ -14,6 +30,8 @@ Install from NuGet: Install-Package Destructurama.Attributed ``` +# Usage + Modify logger configuration: ```csharp @@ -24,14 +42,13 @@ var log = new LoggerConfiguration() ... ``` - -#### Changing a property name +## 1. Changing a property name Apply the `LogWithName` attribute: -```cs +```csharp using Destructurama.Attributed; ... public class PersonalData @@ -43,14 +60,13 @@ public class PersonalData snippet source | anchor - -## Ignoring a property +## 2. Ignoring a property Apply the `NotLogged` attribute: -```cs +```csharp using Destructurama.Attributed; ... public class LoginCommand @@ -68,14 +84,14 @@ When the object is passed using `{@...}` syntax the attributes will be consulted -```cs +```csharp var command = new LoginCommand { Username = "logged", Password = "not logged" }; log.Information("Logging in {@Command}", command); ``` snippet source | anchor -#### Ignoring a property if it has the default value +## 3. Ignoring a property if it has default value Apply the `NotLoggedIfDefault` attribute: @@ -92,7 +108,7 @@ public class LoginCommand } ``` -#### Ignoring a property if it has the null value +## 4. Ignoring a property if it has null value Apply the `NotLoggedIfNull` attribute: @@ -100,57 +116,55 @@ Apply the `NotLoggedIfNull` attribute: public class LoginCommand { /// - /// `null` value results in removed property + /// `null` value results in removed property /// [NotLoggedIfNull] public string Username { get; set; } /// - /// Can be applied with [LogMasked] or [LogReplaced] attributes - /// `null` value results in removed property - /// "123456789" results in "***" + /// Can be applied with [LogMasked] or [LogReplaced] attributes + /// `null` value results in removed property + /// "123456789" results in "***" /// - [NotLoggedIfNull] [LogMasked] + [NotLoggedIfNull] + [LogMasked] public string Password { get; set; } /// - /// Attribute has no effect on non-reference and non-nullable types + /// Attribute has no effect on non-reference and non-nullable types /// [NotLoggedIfNull] public int TimeStamp { get; set; } } ``` -Ignore null properties can be globally applied during initialization without need to apply attributes: +Ignore null properties can be globally applied during logger configuration without need to apply attributes: ```csharp var log = new LoggerConfiguration() .Destructure.UsingAttributes(x => x.IgnoreNullProperties = true) ... ``` +## 5. Treating types and properties as scalars -## Treating types and properties as scalars - -To prevent destructuring of a type or property at all, apply the `[LogAsScalar]` attribute. +To prevent destructuring of a type or property at all, apply the `LogAsScalar` attribute. - -## Masking a string property +## 6. Masking a string property Apply the `LogMasked` attribute with various settings: - - **Text:** If set, the property value will be set to this text. - - **ShowFirst:** Shows the first x characters in the property value. - - **ShowLast:** Shows the last x characters in the property value. - - **PreserveLength:** If set, it will swap out each character with the default value. Note that this property will be ignored if Text has been set to custom value. +- **Text:** If set, the property value will be set to this text. +- **ShowFirst:** Shows the first x characters in the property value. +- **ShowLast:** Shows the last x characters in the property value. +- **PreserveLength:** If set, it will swap out each character with the default value. Note that this property will be ignored if Text has been set to custom value. Note that masking also works for properties of type `IEnumerable` or derived from it, for example, `string[]` or `List`. - ### Examples -```cs +```csharp using Destructurama.Attributed; ... public class CustomizedMaskedLogs @@ -273,12 +287,12 @@ public class CustomizedMaskedLogs snippet source | anchor - -## Masking a string property with regular expressions +## 7. Masking a string property with regular expressions Apply the `LogReplaced` attribute on a string to apply a RegEx replacement during Logging. -This is applicable in scenarios which a string contains both Sensitive and Non-Sensitive information. An example of this could be a string such as "__Sensitive|NonSensitive__". Then apply the attribute like the following snippet: +This is applicable in scenarios when a string contains both Sensitive and Non-Sensitive information. +An example of this could be a string such as "__Sensitive|NonSensitive__". Then apply the attribute like the following snippet: ```csharp [LogReplaced(@"([a-zA-Z0-9]+)\|([a-zA-Z0-9]+)", "***|$2")] @@ -298,29 +312,28 @@ __Constructor arguments__: - **replacement:** The string that will be applied by RegEx. __Available properties__: - - **Options:** The [RegexOptions](https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regexoptions?view=netcore-3.1) that will be applied. Defaults to __RegexOptions.None__ - - **Timeout:** A time-out interval to evaluate regular expression. Defaults to __Regex.InfiniteMatchTimeout__ - + - **Options:** The [RegexOptions](https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regexoptions?view=netcore-3.1) that will be applied. Defaults to __RegexOptions.None__. + - **Timeout:** A time-out interval to evaluate regular expression. Defaults to __Regex.InfiniteMatchTimeout__. ### Examples -```cs +```csharp public class WithRegex { - const string RegexWithVerticalBars = @"([a-zA-Z0-9]+)\|([a-zA-Z0-9]+)\|([a-zA-Z0-9]+)"; + private const string REGEX_WITH_VERTICAL_BARS = @"([a-zA-Z0-9]+)\|([a-zA-Z0-9]+)\|([a-zA-Z0-9]+)"; /// /// 123|456|789 results in "***|456|789" /// - [LogReplaced(RegexWithVerticalBars, "***|$2|$3")] + [LogReplaced(REGEX_WITH_VERTICAL_BARS, "***|$2|$3")] public string? RegexReplaceFirst { get; set; } /// /// 123|456|789 results in "123|***|789" /// - [LogReplaced(RegexWithVerticalBars, "$1|***|$3")] + [LogReplaced(REGEX_WITH_VERTICAL_BARS, "$1|***|$3")] public string? RegexReplaceSecond { get; set; } } ```