Rauchtech.Logging 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Rauchtech.Logging --version 1.0.3
NuGet\Install-Package Rauchtech.Logging -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rauchtech.Logging" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rauchtech.Logging --version 1.0.3
#r "nuget: Rauchtech.Logging, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rauchtech.Logging as a Cake Addin
#addin nuget:?package=Rauchtech.Logging&version=1.0.3

// Install Rauchtech.Logging as a Cake Tool
#tool nuget:?package=Rauchtech.Logging&version=1.0.3

CustomLogs

Log implementation class to facilitate the logging of complex workflows

Startup

1 - To work, it must be registered using the "RegisterCustomLog()" command.

    services.RegisterCustomLog();

2 - Using dependency injection, it works similar to the ILogger:

    private readonly ICustomLog<T> _logger;

    public T(ICustomLog<T> logger)
    {
         _logger = logger;
    }

Default Use Events

AddKey: Used to add key information in the logs. The Behavior can vary following the sequence or the hole scope.

  • string key (required): Name of the key, it will be normalized using "Snake Case". Ex: AsTest ⇒ as_test
  • object value (required): Value of the key, can be any object. </br>

LogCustom: Used to add a new Log register.

  • LogLevel logLevel (required) - Severity of the log (Microsoft.Extensions.Logging)
  • LogType? logType = LogType.Log - used to define between "Log" and "Dashboard" information
  • EventId? eventId = null - EventId in case it's being used (Microsoft.Extensions.Logging.EventId)
  • Exception exception = null - Exception
  • string message = null - Simple message
  • string? sourceContext = null - Do not send
  • [CallerMemberName] string memberName = null - Do not send
  • [CallerLineNumber] int sourceLineNumber = 0 - Do not send
  • params ValueTuple< string, object> args - Tupple array (Name, Objet), the objects will be serialized using Json
    new (string, object)[]
    {
        ("IsNewFlow", message.IsNewFlow),
        ("HasNewFlow", message.HasNewFlow),
        ("BusinessType", message.BusinessType)
    });

#LogAspect

With Aspects we can inject events into methods, in the case of this Library, Begin, Finish and Exception events. To use this, we need to have a ICustomLog initialized in the class and use the decoration [LogAspect] as in the sample.

[LogAspect]
public void DemoMethod()
{
}

Configuration:

  • APPINSIGHTS_INSTRUMENTATIONKEY (required) (string): Application Insights instrumentation Key.
  • APPLICATIONINSIGHTS_CONNECTION_STRING (required) (string): Application Insights connection string.
  • ApplicationName (required) (string): string Sets the ApplicationName property at the Log custom column
  • LogLevel (required) (string): Severity of the log (Microsoft.Extensions.Logging), determine the lower level accepted and ignores all the others.
        //
        // Summary:
        //     Logs that contain the most detailed messages. These messages may contain sensitive
        //     application data. These messages are disabled by default and should never be
        //     enabled in a production environment.
        Trace,
        //
        // Summary:
        //     Logs that are used for interactive investigation during development. These logs
        //     should primarily contain information useful for debugging and have no long-term
        //     value.
        Debug,
        //
        // Summary:
        //     Logs that track the general flow of the application. These logs should have long-term
        //     value.
        Information,
        //
        // Summary:
        //     Logs that highlight an abnormal or unexpected event in the application flow,
        //     but do not otherwise cause the application execution to stop.
        Warning,
        //
        // Summary:
        //     Logs that highlight when the current flow of execution is stopped due to a failure.
        //     These should indicate a failure in the current activity, not an application-wide
        //     failure.
        Error,
        //
        // Summary:
        //     Logs that describe an unrecoverable application or system crash, or a catastrophic
        //     failure that requires immediate attention.
        Critical,
        //
        // Summary:
        //     Not used for writing log messages. Specifies that a logging category should not
        //     write any messages.
        None
  • EnableScopeKeys (bool): Sets if the Keys will be used from the usage onwards or if they will be set for the entire scope.

    • Warning : If this property is set to true, the logs will only be fired after calling "Finish()", and it's advised to put this at the finish clause of trye/cath in the Function call.
    try
    {
    }
    catch
    {
    }
    finish
    {
        _logger.Finish();
    }

Note:

Use the AddKey method before any other Log in case the "EnableScopeKeys" is not true.

Application Insights Customization

At the resource's Insights, go to Monitoring/Logs, and in the query put this Kusto script bellow:

let All = () {
    customEvents
    | where 
        customDimensions.Data != ""
    | union
    exceptions
        | where 
        customDimensions.Data != ""
    | project
        Timestamp = todatetime(customDimensions.Timestamp),
        CurrentStep = tolong(customDimensions.CurrentStep),
        ApplicationName = customDimensions.ApplicationName,
        LogLevel = customDimensions.LogLevel,
        LogType = customDimensions.LogType,
        Source = customDimensions.SourceContext,
        Keys = todynamic(tostring(customDimensions.Keys)),
        Data = todynamic(tostring(customDimensions.Data)),
        Exception = customDimensions.ExceptionDetail
    | order by
        Timestamp desc,
        CurrentStep desc
};
All();

Then save it as a function, the sugested name is CustomLogs

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 0 5/12/2024
2.0.0 0 5/12/2024
1.0.3 233 2/13/2023
1.0.2 218 2/13/2023
1.0.1 207 2/13/2023
1.0.0 218 2/12/2023