OutWit.Common.Logging 1.1.1

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

or

> dotnet add package OutWit.Common.Logging

Streamlining Logging with the Log Aspect

Maintaining logs is critical for debugging and supporting complex applications. Manually adding logging calls everywhere can be tedious and error-prone. The OutWit.Common.Logging package simplifies this process with three powerful aspects: Log, NoLog, and Measure. The source code is available here.

Setting Up the Logger

Before using the logging aspects, initialize the logger. The current implementation is based on Serilog:

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Is(LogEventLevel.Information)
    .Enrich.WithExceptionDetails()
    .WriteTo.File(@"D:\Log\Log.txt",
        rollingInterval: RollingInterval.Day,
        rollOnFileSizeLimit: true,
        fileSizeLimitBytes: 524288)
    .CreateLogger();

The Log Aspect

The Log aspect can be applied to individual methods:

public class Model
{
    [Log]
    public void DoSomething1()
    {
    }

    public void DoSomething2()
    {
    }
}

Or to an entire class:

[Log]
public class Model
{
    public void DoSomething1()
    {
    }

    public void DoSomething2()
    {
    }
}

When applied to a class, it automatically applies to all methods within the class.

What Does the Log Aspect Do?

  1. Exception Handling: Wraps method execution in a try-catch block and logs exceptions with their details.
  2. Method Execution Logging: Logs method calls (excluding property getters/setters) if the logger’s MinimumLevel is Information or lower.
  3. Detailed Property Access Logging: If the logger’s MinimumLevel is Verbose, it also logs property access.

This flexibility allows you to control log verbosity by adjusting the logger's configuration.

The NoLog Aspect

If the Log aspect is applied to a class, but you want to exclude specific methods from logging, you can use the NoLog aspect:

[Log]
public class Model
{
    public void DoSomething1()
    {
    }

    [NoLog]
    public void DoSomething2()
    {
    }
}

The Measure Aspect

To measure the execution time of a method, apply the Measure aspect. This will log the duration in milliseconds:

public class Model
{
    public void DoSomething1()
    {
    }

    [Measure]
    public void DoSomething2()
    {
    }
}

When DoSomething2 is called, the log will include the method’s execution time.

Key Benefits

  • Automates logging for methods and properties.
  • Simplifies exception handling by centralizing logging.
  • Provides flexible control over log verbosity.
  • Enables easy performance measurement.

For more details, check out the article.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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 is compatible.  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 is compatible.  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 is compatible.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on OutWit.Common.Logging:

Package Downloads
OutWit.Common.MVVM

A collection of essential helpers and components for WPF and the MVVM pattern. Includes a ViewModelBase, DelegateCommand, a thread-safe SafeObservableCollection, SortedCollection, powerful binding utilities, and an AOP [Bindable] attribute to easily create DependencyProperties.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 97 6/28/2025
1.1.0 68 6/7/2025
1.0.3 114 3/14/2025
1.0.2 121 12/29/2024
1.0.1 120 11/24/2024
1.0.0 116 10/13/2024