DevInstance.LogScope.Extensions.MicrosoftLogger 10.0.0

dotnet add package DevInstance.LogScope.Extensions.MicrosoftLogger --version 10.0.0
                    
NuGet\Install-Package DevInstance.LogScope.Extensions.MicrosoftLogger -Version 10.0.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="DevInstance.LogScope.Extensions.MicrosoftLogger" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DevInstance.LogScope.Extensions.MicrosoftLogger" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DevInstance.LogScope.Extensions.MicrosoftLogger" />
                    
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 DevInstance.LogScope.Extensions.MicrosoftLogger --version 10.0.0
                    
#r "nuget: DevInstance.LogScope.Extensions.MicrosoftLogger, 10.0.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 DevInstance.LogScope.Extensions.MicrosoftLogger@10.0.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=DevInstance.LogScope.Extensions.MicrosoftLogger&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DevInstance.LogScope.Extensions.MicrosoftLogger&version=10.0.0
                    
Install as a Cake Tool

LogScope.NET Standard: Logging, tracing and profiling

LogScope.NET is a lightweight logging framework designed for tracing, profiling, and logging critical parts of your code. It can seamlessly integrate with popular logging libraries like Log4Net and NLog.

The framework revolves around the concept of a "scope," which can represent a method or a specific part of it. The implementation is based on the IDisposable interface, where calling Dispose method marks the end of the scope.

Additionally, it offers more streamlined coding and shorter lines of code compared to the conventional logging APIs.

Here's an example that illustrates this approach:

class TestClass
{
    IScopeLog classScope;

    public TestClass(IScopeManager manager)
    {
        classScope = manager.CreateLogger(this);
    }

    public void MethodA()
    {
        using (var methodScope = classScope.DebugScope())
        {
            methodScope.D("Wait for 200 msec");
            Thread.Sleep(200);
            methodScope.D("Done.");
            using (var aScope = methodScope.DebugScope("a-scope"))
            {
                aScope.D("Inside of a scope");
            }
            MethodB();
        }
    }

    private void MethodB()
    {
        using (var methodScope = classScope.DebugScope())
        {
            methodScope.D("Inside of method B scope");
            Thread.Sleep(200);
        }
    }
}

Result:

21-01-29 23:07:24--> TestClass:MethodA
21-01-29 23:07:24    TestClass:MethodA:Wait for 200 msec
21-01-29 23:07:25    TestClass:MethodA:Done.
21-01-29 23:07:25--> TestClass:MethodA:a-scope
21-01-29 23:07:25    TestClass:MethodA:a-scope:Inside of a scope
21-01-29 23:07:25<-- TestClass:MethodA:a-scope, time:2.1252 msec
21-01-29 23:07:25--> TestClass:MethodB
21-01-29 23:07:25    TestClass:MethodB:Inside of method B scope
21-01-29 23:07:25<-- TestClass:MethodB, time:212.748 msec
21-01-29 23:07:25<-- TestClass:MethodA, time:480.5525 msec

Setup

LogScope packages are available on NuGet:

Add the package reference to your project:

CLI:

# Core library (.NET 10)
dotnet add package DevInstance.LogScope

# .NET 10+ with dependency injection
dotnet add package DevInstance.LogScope.NET

# Microsoft Logging extension
dotnet add package DevInstance.LogScope.Extensions.MicrosoftLogger

Package Manager:

# Core library (.NET 10)
Install-Package DevInstance.LogScope

# .NET 10+ with dependency injection
Install-Package DevInstance.LogScope.NET

# Microsoft Logging extension
Install-Package DevInstance.LogScope.Extensions.MicrosoftLogger

Initialization

With Dependency Injection

If your application uses dependency injection, call the AddConsoleScopeLogging extension method:

public void ConfigureServices(IServiceCollection services)
{
    services.AddConsoleScopeLogging(LogLevel.DEBUG);
}

Console Application (without DI)

For console applications, instantiate using DefaultScopeLogFactory directly:

var manager = DefaultScopeLogFactory.CreateConsoleLogger(LogLevel.DEBUG);

With Microsoft.Extensions.Logging

For integration with Microsoft's logging framework:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMicrosoftScopeLogging(new DefaultFormattersOptions
    {
        ShowTimestamp = true,
        ShowThreadNumber = true
    });
}

Log Levels

LogScope supports the following log levels:

Level Description
NOLOG Disable logging
ERROR Error messages only
WARNING Warnings and errors
INFO Informational messages
DEBUG Debug messages (verbose)

Documentation

See more information about the API: https://devinstance.net/engineering/logscope

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
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
10.0.0 95 1/20/2026
8.0.0 162 12/19/2024
1.0.1 623 8/24/2022
1.0.0 491 8/22/2022
0.9.4 588 2/14/2022
0.9.2 416 11/30/2021
0.9.1 559 5/30/2021
0.9.0 419 5/4/2021

Release notes for 10.0.0:
- .NET10 Migration
Release notes for 8.0.0:
- .NET8 Migration and minor updates
Release notes for 1.0.1:
- Additional extension method for the formating options
Release notes for 1.0.0:
- Support of LogScope 1.4.2
- Performance optimizations
- First official release