Git Product home page Git Product logo

ogu.extensions.logging.timings's Introduction

Header Ogu.Extensions.Logging.Timings

.NET Core Desktop NuGet Nuget

Introduction

This library brings the feature-rich capabilities of SerilogTimings to Microsoft.Extensions.Logging. Designed to seamlessly integrate with Microsoft.Extensions.Logging, this library enables developers to incorporate structured timing measurements into their log entries, enhancing the logging experience and providing valuable performance insights. If you are already familiar with SerilogTimings, you'll find it easy to use this library as it maintains the same ease of use and flexibility while targeting Microsoft.Extensions.Logging.

Features

  • Structured Timing Logs: Add precise timing information to your log entries using structured logs, enhancing your ability to analyze and diagnose application performance.
  • Effortless Integration: Seamlessly integrate the timing functionality into your existing Microsoft.Extensions.Logging workflow without any additional dependencies.
  • Flexibility: Enjoy the benefits of timings in your Microsoft.Extensions.Logging-based projects, keeping the freedom to choose your preferred logging providers.

Installation

You can install the library via NuGet Package Manager:

dotnet add package Ogu.Extensions.Logging.Timings

Usage

example 1:

using (logger.TimeOperation("User: {UserId} is saving to database", userId))
{
    ...
}

output

info: Timings.Console.Program[0]
      User: 1 is saving to database completed in 0.4712ms

example 2:

using (var op = logger.BeginOperation("User: {UserId} is removing from database.", userId))
{
    if (true)
    {
        op.Abandon();
    }

    // Do some operations

    op.Complete("Username", "ogulcanturan");
}

output

warn: Timings.Console.Program[0]
      User: 1 is removing from database. abandoned in 0.0581ms

example 3:

using (var op = logger.BeginOperation("You will not see this message on console, because of this statement => 'op.Cancel()'"))
{
    if (true)
    {
        op.Cancel();
    }

    // Do some operations

    op.Complete();
}

output

example 4:

using (var op = logger.BeginOperation("Doing some operations..."))
{
    try
    {
        int calculation = int.Parse("You cannot parse this to number!");
    }
    catch (Exception ex)
    {
        op.SetException(ex);
    }

    op.Complete(); // If you don't call 'op.Complete()' it will call implicitly 'op.Abandon()'
}

output

info: Timings.Console.Program[0]
      Doing some operations... completed in 1434.2430ms
      System.FormatException: The input string 'You cannot parse this to number!' was not in a correct format.
         at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, ReadOnlySpan`1 value, TypeCode type)
         at System.Int32.Parse(String s)
         at Timings.Console.Program.Main(String[] args) in ...

example 5:

using (logger.OperationAt(LogLevel.Trace).Time("App is closing..."))
{
    // Do some operations
}

output

trce: Timings.Console.Program[0]
      App is closing... completed in 0.0015ms

Sample Application

A sample application demonstrating the usage of Ogu.Extensions.Logging.Timings can be found here.

ogu.extensions.logging.timings's People

Contributors

ogulcanturan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.