LokiLogger.Fody 3.0.13

dotnet add package LokiLogger.Fody --version 3.0.13
NuGet\Install-Package LokiLogger.Fody -Version 3.0.13
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="LokiLogger.Fody" Version="3.0.13" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LokiLogger.Fody --version 3.0.13
#r "nuget: LokiLogger.Fody, 3.0.13"
#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 LokiLogger.Fody as a Cake Addin
#addin nuget:?package=LokiLogger.Fody&version=3.0.13

// Install LokiLogger.Fody as a Cake Tool
#tool nuget:?package=LokiLogger.Fody&version=3.0.13

LokiLogger v3

Log anything within your application with under ten lines of code.

What's so nice about this logger?

  1. Simplicity:
    It's really simple. Use the logger as a method attribute in your C# code. Everything else is already handled by the logger.
  2. Implicit usage:
    When you added the method attribute, it's done. Really. Don't worry about logging. It's done.
  3. No performance impact:
    The logging calls are compiled into the binary. The overhead is not more than a method call. You won't ever feel the difference.
  4. Additional log types:
    There are several different types of events that can be handled and filtered differently.

How to use?

It's very simple. Just add the adapter (the "target" you're writing your logs to) using the following example:

Loki.UpdateAdapter(new BasicLoggerAdapter());

If an adapter should only be used by specific log levels:

Loki.UpdateAdapter(new BasicLoggerAdapter(), new List<LogLevel>{LogLevel.Debug});

You can also remove an adapter:

Loki.RemoveAdapter(adapter);

Traditional logs

Of course, normal log messages using traditional explicit logging are supported as well:

Loki.Debug("Nobody cares about debug info");
Loki.Information("This may help finding problems");
Loki.Warning("This is relatively important");
Loki.Error("This is more important");
Loki.Critical("This is very important!");

You can also add any object to the method all, e.g.:

Loki.Warning("Maybe you have a problem:", new object());

Exception handling

Exceptions are very important. However, sometimes nobody cares about them. So, you can define this behavior by using the log levels accordingly.

Loki.ExceptionDebug("Nobody cares about debug info");
Loki.ExceptionInformation("This may help finding problems");
Loki.ExceptionWarning("This is relatively important");
Loki.ExceptionError("This is more important");
Loki.ExceptionCritical("This is very important!");

Return capture

Returns are very important. Sometimes... 😉
The default log level of returns is Debug.

Loki.Return(returnValue);

How to add this functionality to your project?

Basic usage

Just add Fody to your Project. Then add <LokiLogger/> in the FodyWeavers.xml. That's it. You're ready to go!

Add the attribute Loki over every method or class you want to log. Every method call and exception will be logged, thanks to Fody. The execution time is additionally logged.

[Loki]
public int do(int x){
    return x++;
}

⚠️ Note: Don't use that feature in very frequently called methods. The performance impact is normally very low. But you may encounter "problems" when using the attribute on an extremely frequently used method.

Use in ASP Core

Add the following snippet in the StartUp.cs file in the method ConfigureServices:

services.AddLokiObjectLogger();

Adapt and add the following part in the method Configure in order to use LokiReporter:

app.UseLokiLogger(
	x => {
	    x.UseMiddleware = true;
	    x.Secret = "1234";
	    x.HostName = "<hostname>";
	    x.DefaultLevel = LogLevel.Debug;
	}
);

Details

By default, the three basic log events are:

  • Invoke when entering a method
  • Exception when an exception occurs
  • Rest when there happens a REST-call
  • Return when returning a value

We always want to know, where an event happened. Thus, it's implemented using [CallerMemberName] to avoid reflection overhead.

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. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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
3.0.13 793 2/5/2020
3.0.12 682 2/5/2020
3.0.11 696 2/5/2020
3.0.10 706 2/5/2020
3.0.9 726 12/11/2019
3.0.8 692 11/10/2019
3.0.7 687 11/7/2019
3.0.6 701 10/7/2019
3.0.1 693 9/10/2019
3.0.0 731 9/10/2019
2.2.4 711 7/29/2019
0.0.1 742 9/10/2019