MondoCore.Log 2.3.0

dotnet add package MondoCore.Log --version 2.3.0
                    
NuGet\Install-Package MondoCore.Log -Version 2.3.0
                    
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="MondoCore.Log" Version="2.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MondoCore.Log" Version="2.3.0" />
                    
Directory.Packages.props
<PackageReference Include="MondoCore.Log" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MondoCore.Log --version 2.3.0
                    
#r "nuget: MondoCore.Log, 2.3.0"
                    
#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.
#:package MondoCore.Log@2.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MondoCore.Log&version=2.3.0
                    
Install as a Cake Addin
#tool nuget:?package=MondoCore.Log&version=2.3.0
                    
Install as a Cake Tool

MondoCore.Log

Classes for logging

<br>

Dependency Injection

In your dependency injection code create a singleton instance of Log

public class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
        // Register the main Log class as a singleton.
        builder.Services.AddSingleton<ILog>( (p)=> 
        {
            var log = new Log();

            // Use GetService to get the TelemetryConfiguration to share with the host
            log.Register( new ApplicationInsights( p.GetService<TelemetryConfiguration>() ),
                          new Splunk("???"), types: new List<Telemetry.TelemetryType> { Telemetry.TelemetryType.Event } ); // Log only WriteEvent telemetry

            return log;
        );

        // Register IRequestLog as scoped. That same instance will be returned within the scope of a function invocation
        builder.Services.AddScoped<IRequestLog, RequestLog>();
    }
}

<br>

Logging with ILog

Inject the ILog interface

using MondoCore.Log;

public class CoolClass
{
    private readonly ILog _log;

    public CoolClass(ILog log)
    {
        _log = log;
    }

    public async Task DoSomething(string name)
    {
        try
        {
            _log.WriteEvent("Something cool", new {Make = "Chevy", Model = "Corvette", Name = name } );

            if(blah)
                await _log.WriteError(new Exception("Data error"), Telemetry.LogSeverity.Warning, new { Class = "CoolClass", Function = "DoSomething" } )
        }
        catch(Exception ex)
        {
            // The anonymous object will be logged as two properties: "Class" and "Function"
            await _log.WriteError(ex, Telemetry.LogSeverity.Critical, new { Class = "CoolClass", Function = "DoSomething" } )
        }
    }
}

<br>

Logging with IRequestLog

By creating a scoped RequestLog you can set properties that will exist for every log within that scope. IRequestLog is derived from ILog so you just treat it as an ILog

using MondoCore.Log;

public class CoolClass
{
    private readonly IRequestLog _log;

    public CoolClass(IRequestLog log)
    {
        _log = log;
    }

    public async Task DoSomething(string name)
    {
        // This property will be added to all subsequent log calls during the lifetime of IRequestLog
        _log.SetProperty("Name", name);

        try
        {
            // Do something...
            // ...

            _log.WriteEvent("Something cool", new {Make = "Chevy", Model = "Corvette"} );

            if(blah)
                await _log.WriteError(new Exception("Data error"), Telemetry.LogSeverity.Warning, new { Class = "CoolClass", Function = "DoSomething" } )
        }
        catch(Exception ex)
        {
            // The anonymous object will be logged as two properties: "Class" and "Function"
            await _log.WriteError(ex, new { Class = "CoolClass", Function = "DoSomething" } )
        }
    }

    // Nested IRequestLog
    public async Task DoSomethingElse(string name)
    {
        using(var requestLog = log.NewRequest("CoolClass.DoSomethingElse))
        {
            // These properties will be added to all log calls within this using block (you must use the local log var)
            requestLog.SetProperty("Name", name);
            requestLog.SetProperty("Class", nameof(CoolClass));
            requestLog.SetProperty("Method", nameof(DoSomethingElse));

            try
            {
                // Do something...
                // ...

                requestLog.WriteEvent("Something cool", new {Make = "Chevy", Model = "Corvette"} );

                if(blah)
                    await requestLog.WriteError(new Exception("Data error"), Telemetry.LogSeverity.Warning)
            }
            catch(Exception ex)
            {
                await requestLog.WriteError(ex)
            }
        }
    }
}

<br>

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on MondoCore.Log:

Package Downloads
MondoCore.Azure.ApplicationInsights

Implementation of ILog interface for Application Insights

MondoCore.ApplicationInsights

Implementation of ILog interface for Application Insights

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.3.0 188 11/30/2024
2.2.1 155 10/9/2024
2.2.0 177 9/30/2024
2.1.0 136 7/23/2024
2.0.0 3,200 11/26/2023
1.6.0 2,277 10/6/2023
1.5.1 1,714 3/20/2021
1.5.0 589 2/20/2021
1.4.0 561 2/8/2021
1.3.0 626 1/27/2021
1.2.1 631 1/10/2021
1.2.0 745 12/6/2020
1.1.0 728 9/19/2020
1.0.1 637 8/31/2020
1.0.0 825 8/8/2020

Add availability telemetry