OutWit.Common.Logging
1.0.0
See the version list below for details.
dotnet add package OutWit.Common.Logging --version 1.0.0
NuGet\Install-Package OutWit.Common.Logging -Version 1.0.0
<PackageReference Include="OutWit.Common.Logging" Version="1.0.0" />
paket add OutWit.Common.Logging --version 1.0.0
#r "nuget: OutWit.Common.Logging, 1.0.0"
// Install OutWit.Common.Logging as a Cake Addin #addin nuget:?package=OutWit.Common.Logging&version=1.0.0 // Install OutWit.Common.Logging as a Cake Tool #tool nuget:?package=OutWit.Common.Logging&version=1.0.0
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?
- Exception Handling: Wraps method execution in a try-catch block and logs exceptions with their details.
- Method Execution Logging: Logs method calls (excluding property getters/setters) if the logger’s MinimumLevel is Information or lower.
- 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 | Versions 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. |
.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. |
-
.NETStandard 2.0
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- OutWit.Common.Aspects (>= 1.0.0)
- Serilog (>= 4.0.2)
- Serilog.Exceptions (>= 8.4.0)
- Serilog.Extensions.Logging (>= 8.0.0)
- Serilog.Sinks.Debug (>= 3.0.0)
- Serilog.Sinks.File (>= 6.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on OutWit.Common.Logging:
Package | Downloads |
---|---|
OutWit.Common.MVVM
Base MVVM snipets and aspects: - Commands - Binding utils and aspects - View model base |
GitHub repositories
This package is not used by any popular GitHub repositories.