https://github.com/bigbuildbench/destructurama_attributed
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.3%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: BigBuildBench
- License: apache-2.0
- Language: C#
- Default Branch: master
- Size: 269 KB
Statistics
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
- Releases: 0
Metadata Files
README.md
Destructurama.Attributed
This package makes it possible to manipulate how objects are logged to Serilog using attributes.
Installation
Install from NuGet:
powershell
Install-Package Destructurama.Attributed
Usage
Modify logger configuration:
csharp
using Destructurama;
...
var log = new LoggerConfiguration()
.Destructure.UsingAttributes()
...
1. Changing a property name
Apply the LogWithName attribute:
cs
public class PersonalData
{
[LogWithName("FullName")]
public string? Name { get; set; }
}
snippet source | anchor
<!-- endSnippet -->
2. Ignoring a property
Apply the NotLogged attribute:
```cs public class LoginCommand { public string? Username { get; set; }
[NotLogged]
public string? Password { get; set; }
} ``` snippet source | anchor <!-- endSnippet -->
When the object is passed using {@...} syntax the attributes will be consulted.
cs
var command = new LoginCommand { Username = "logged", Password = "not logged" };
_log.Information("Logging in {@Command}", command);
snippet source | anchor
<!-- endSnippet -->
3. Ignoring a property if it has default value
Apply the NotLoggedIfDefault attribute:
```csharp public class LoginCommand { public string Username { get; set; }
[NotLoggedIfDefault] public string Password { get; set; }
[NotLoggedIfDefault] public DateTime TimeStamp { get; set; } } ```
4. Ignoring a property if it has null value
Apply the NotLoggedIfNull attribute:
``csharp
public class LoginCommand
{
/// <summary>
///null` value results in removed property
///
[NotLoggedIfNull]
public string Username { get; set; }
/// null value results in removed property
/// "123456789" results in "***"
///
///
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
To prevent destructuring of a type or property at all, apply the LogAsScalar attribute.
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.
Note that masking also works for properties of type IEnumerable<string> or derived from it, for example, string[] or List<string>.
Examples
```cs
public class CustomizedMaskedLogs
{
///
/// <summary>
/// [123456789,123456789,123456789] results in [***,***,***]
/// </summary>
[LogMasked]
public string[]? DefaultMaskedArray { get; set; }
/// <summary>
/// 123456789 results in "*********"
/// </summary>
[LogMasked(PreserveLength = true)]
public string? DefaultMaskedPreserved { get; set; }
/// <summary>
/// "" results in "***"
/// </summary>
[LogMasked]
public string? DefaultMaskedNotPreservedOnEmptyString { get; set; }
/// <summary>
/// 123456789 results in "#"
/// </summary>
[LogMasked(Text = "_REMOVED_")]
public string? CustomMasked { get; set; }
/// <summary>
/// 123456789 results in "#"
/// </summary>
[LogMasked(Text = "")]
public string? CustomMaskedWithEmptyString { get; set; }
/// <summary>
/// 123456789 results in "#########"
/// </summary>
[LogMasked(Text = "#", PreserveLength = true)]
public string? CustomMaskedPreservedLength { get; set; }
/// <summary>
/// 123456789 results in "123******"
/// </summary>
[LogMasked(ShowFirst = 3)]
public string? ShowFirstThreeThenDefaultMasked { get; set; }
/// <summary>
/// 123456789 results in "123******"
/// </summary>
[LogMasked(ShowFirst = 3, PreserveLength = true)]
public string? ShowFirstThreeThenDefaultMaskedPreservedLength { get; set; }
/// <summary>
/// 123456789 results in "***789"
/// </summary>
[LogMasked(ShowLast = 3)]
public string? ShowLastThreeThenDefaultMasked { get; set; }
/// <summary>
/// 123456789 results in "******789"
/// </summary>
[LogMasked(ShowLast = 3, PreserveLength = true)]
public string? ShowLastThreeThenDefaultMaskedPreservedLength { get; set; }
/// <summary>
/// 123456789 results in "123REMOVED"
/// </summary>
[LogMasked(Text = "_REMOVED_", ShowFirst = 3)]
public string? ShowFirstThreeThenCustomMask { get; set; }
/// <summary>
/// 123456789 results in "123_REMOVED_"
/// </summary>
[LogMasked(Text = "_REMOVED_", ShowFirst = 3, PreserveLength = true)]
public string? ShowFirstThreeThenCustomMaskPreservedLengthIgnored { get; set; }
/// <summary>
/// 123456789 results in "_REMOVED_789"
/// </summary>
[LogMasked(Text = "_REMOVED_", ShowLast = 3)]
public string? ShowLastThreeThenCustomMask { get; set; }
/// <summary>
/// 123456789 results in "_REMOVED_789"
/// </summary>
[LogMasked(Text = "_REMOVED_", ShowLast = 3, PreserveLength = true)]
public string? ShowLastThreeThenCustomMaskPreservedLengthIgnored { get; set; }
/// <summary>
/// 123456789 results in "123***789"
/// </summary>
[LogMasked(ShowFirst = 3, ShowLast = 3)]
public string? ShowFirstAndLastThreeAndDefaultMaskInTheMiddle { get; set; }
/// <summary>
/// 123456789 results in "123456789", no mask applied
/// </summary>
[LogMasked(ShowFirst = -1, ShowLast = -1)]
public string? ShowFirstAndLastInvalidValues { get; set; }
/// <summary>
/// 123456789 results in "123***789"
/// </summary>
[LogMasked(ShowFirst = 3, ShowLast = 3, PreserveLength = true)]
public string? ShowFirstAndLastThreeAndDefaultMaskInTheMiddlePreservedLength { get; set; }
/// <summary>
/// 123456789 results in "123_REMOVED_789"
/// </summary>
[LogMasked(Text = "_REMOVED_", ShowFirst = 3, ShowLast = 3)]
public string? ShowFirstAndLastThreeAndCustomMaskInTheMiddle { get; set; }
/// <summary>
/// 123456789 results in "123_REMOVED_789". PreserveLength is ignored"
/// </summary>
[LogMasked(Text = "_REMOVED_", ShowFirst = 3, ShowLast = 3, PreserveLength = true)]
public string? ShowFirstAndLastThreeAndCustomMaskInTheMiddlePreservedLengthIgnored { get; set; }
} ``` snippet source | anchor <!-- endSnippet -->
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 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")] public property Information { get; set; }
// Will log: "***|NonSensitive" ```
LogReplaced attribute is available with the following constructor:
csharp
LogReplaced(string pattern, string replacement)
Constructor arguments: - pattern: The pattern that should be applied on value. - replacement: The string that will be applied by RegEx.
Available properties: - Options: The RegexOptions that will be applied. Defaults to RegexOptions.None. - Timeout: A time-out interval to evaluate regular expression. Defaults to Regex.InfiniteMatchTimeout.
Examples
```cs public class WithRegex { private const string REGEXWITHVERTICAL_BARS = @"([a-zA-Z0-9]+)|([a-zA-Z0-9]+)|([a-zA-Z0-9]+)";
/// <summary>
/// 123|456|789 results in "***|456|789"
/// </summary>
[LogReplaced(REGEX_WITH_VERTICAL_BARS, "***|$2|$3")]
public string? RegexReplaceFirst { get; set; }
/// <summary>
/// 123|456|789 results in "123|***|789"
/// </summary>
[LogReplaced(REGEX_WITH_VERTICAL_BARS, "$1|***|$3")]
public string? RegexReplaceSecond { get; set; }
} ``` snippet source | anchor <!-- endSnippet -->
Benchmarks
The results are available here.
Owner
- Name: BigBuildBench
- Login: BigBuildBench
- Kind: organization
- Repositories: 1
- Profile: https://github.com/BigBuildBench
abbr. B3, benchmarking the repo-level understanding capability of your LLMs by reconstructing project build-file.
GitHub Events
Total
- Push event: 1
- Pull request event: 3
- Create event: 9
Last Year
- Push event: 1
- Pull request event: 3
- Create event: 9
Dependencies
- actions/checkout v4 composite
- actions/setup-dotnet v4 composite
- benchmark-action/github-action-benchmark v1 composite
- actions/checkout v4 composite
- actions/setup-dotnet v4 composite
- github/codeql-action/analyze v3 composite
- github/codeql-action/init v3 composite
- actions/labeler v5 composite
- actions/checkout v4 composite
- actions/setup-dotnet v4 composite
- actions/upload-artifact v4 composite
- actions/checkout v4 composite
- actions/github-script v7 composite
- actions/setup-dotnet v4 composite
- actions/upload-artifact v4 composite
- actions/stale v9 composite
- actions/checkout v4 composite
- actions/setup-dotnet v4 composite
- codecov/codecov-action v4 composite