Giter Club home page Giter Club logo

ark.tools's Introduction

image

Ark.Tools

This is a set of core libraries developed and maintained by Ark as a set of helper or extensions of the libraries Ark choose to use in their LOB applications.

Getting Started

All libraries are provided in NuGet.

Support for .NET Framework 4.7.1,.NET Standard 2.x, .NET 6.0. Support for other frameworks is up-for-grabs ;)

Quick Start

The main library used by Ark in its stack are

If you want to learn more about each project, look the respective Readme when present or directly at code. Documentation improvements are up-for-grabs ;)

Upgrade to NLog v5 in Ark.Tools>=v4.5

In v4.5 has been revisited the NLog integration and helpers to make use of new features.

NLog 'default' Configuration

The best way to configure NLog is

    Host.CreateDefaultBuilder(args)
        .ConfigureNLog()
        .ConfigureServices(...)
    ;

is equivalent to

    .ConfigureLogging((ctx,l) =>
    {
        var appName = Assembly.GetEntryAssembly().GetName().Name;
        NLogConfigurer
            .For(appName)
            // Load default settings from IConfiguration
            .WithDefaultTargetsAndRulesFromConfiguration(ctx.Configuration)
            .Apply();

        l.ClearProviders(); // remove all Microsoft providers
        l.AddNLog(); // sink all Microsoft.Logging logs to NLog
    })

.WithDefaultTargetsAndRulesFromAppSettings() and .WithDefaultTargetsAndRulesFromCloudSettings() exists for older Configuration sources.

The NLog auto-configurer expect the following settings:

  • NLog.Database for SQL Server target. The table name is passed in as paramter to the configuration extension method.
  • NLog.Smtp for the Mail target
  • NLog:SlackWebHook for the Slack target. By default only Fatal and LoggerName=Slack.* are sent.
  • APPINSIGHTS_INSTRUMENTATIONKEY or ApplicationInsights:InstrumentationKey for the ApplicationInsights target. By default only >=Error are sent.

NLog Structured Logging

Logging represent a non trivial part of the CPU consumption of a running Assembly: strings are bad, concateneting them is costly. Log Messages are also generally structured to present some context variables which are of interest.

[email protected] introduced StructuredLogging template support. [email protected] (same version, just a coincidence...) supports writing these captured properties in ApplicationInsights and Database Targets.

StructuredLogging is also more performant of string interpolation: string interpolation ($"Message {variable}") SHALL NOT be used for Logging! String interpolation is always performed even usually disabled levels like Trace or Debug causing a performance loss. Additionally the variables are not captured and cannot be used for log analysis querying the JSON fields.

// BAD
_logger.Info($"Logon by {user} from {ip_address}");

// GOOD
_logger.Info("Logon by {user} from {ip_address}", user, ip_address); // ordered by position

NLog Slack (>=v4.4)

Starting [email protected] there is support for Logging to Slack via WebHook.

The Configuration auto-loaders like WithDefaultTargetsAndRulesFromConfiguration() looks for a NLog:SlackWebHook and if non-empty configure to send Logs as chat message to Slack. The default Rules are either:

  • LoggerName="Slack.*" (created via _slackLogger = LogManager.CreateLogger("Slack.MyStuff");)
  • Level==Fatal

NLog ApplicationInsights

Starting [email protected] there is support for Logging to ApplicationInsights.

The Configuration auto-loaders like WithDefaultTargetsAndRulesFromConfiguration() looks for the Microsoft's default settings like APPINSIGHTS_INSTRUMENTATIONKEY and ApplicationInsights:InstrumentationKey.

The default Rules to log any Error or Fatal to ApplicationInsights, including any Exception and StructuredLogging properties.

Migrate from v2 to v3

  • BREAKING: Microsoft.AspNetCore v5
    • change netcoreapp3.1 to net5.0 on all projects referencing Ark.Tools.AspNetCore.* projects
  • BREAKING: from System.Data.SqlClient to Microsoft.Data.SqlClient
    • remove any Nuget reference to System.Data.SqlClient and replace, where needed, with Microsoft.Data.SqlClient
  • BREAKING: upgraded to Flurl v3
    • most usages should be fine, but those that expected Flurl method to return a HttpMessageResponse, as not returns IFlurlResponse Disposable!
  • BREAKING: change to AspNetCore base Startup on RegisterContainer()
    • RegisterContainer() no longer takes IApplicationBuilder parameter but a IServiceProvider as the Container registration has been moved during ConfigureServices()
    • this affects mostly those cases where IServiceProvider was used to check for Tests overrides of mocked services
    • Use IHostEnvironment or services.HasService if possible instead of relying on IServiceProvider
  • BREAKING: change to AspNetCore Startups. Now defaults to System.Text.Json instead of Newtonsoft.Json.
    • Use the parameter useNewtonsoftJson: true of base ctor to keep old behaviour
    • Migrate from the Ark.Tools.SystemTextJson.JsonPolymorphicConverter instead of Ark.Tools.NewtonsoftJson.JsonPolymorphicConverter

Contributing

Feel free to send PRs or to raise issues if you spot them. We try our best to improve our libraries. Please avoid adding more dependencies to 3rd party libraries.

Links

License

This project is licensed under the MIT License - see the LICENSE file for details.

Licence Claims

A part of this code is taken from StackOverflow or blogs or example. Where possible we included reference to original links but if you spot some missing Acknolegment please open an Issue right away.

ark.tools's People

Contributors

andreacuneo avatar arkcecchi avatar dependabot[bot] avatar fabiobrizzolara avatar jacopocinaark avatar kwon0408 avatar marcogix avatar michaelgeraghty avatar mortoize avatar peterrimmer71 avatar sicurezza avatar stefanoursino avatar thieum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ark.tools's Issues

Eliminate STJ dependency for net 6

Is your feature request related to a problem? Please describe.
I want to minimise dependencies in my project by utilising framework dependencies wherever possible

Describe the solution you'd like
I want the package to not have an explicit dependency on System.Text.Json as it can be provided by the framework when targeting net 6.

Describe alternatives you've considered
Accept the additional dependency

Additional context
n/a

Sunlighter.AsyncQueueLib bug fix

Github says you are using Sunlighter.AsyncQueueLib. If this is still the case, you might want to update to the latest version (1.0.6) if possible. An important bug has been fixed.

ActivityIdLayoutRenderer - Wrong class attributes

Think you have applied the wrong attributes here, as they are very special:

[LayoutRenderer("ark.activityid")]
[AppDomainFixedOutput]
[ThreadAgnostic]
public class ActivityIdLayoutRenderer : LayoutRenderer

  • [ThreadAgnostic] - Means that the layoutrenderer will generate the same output independent on which threads it happens (Ex. like the FormattedMessage). But this is not true for System.Diagnostics.Activity.Id since it is only valid for the active thread logging, and not available if writing happens on a background-thread (<targets async="true">).

  • [AppDomainFixedOutput] - Means that the layoutrenderer will always generate the same output independent of time and thread (Ex. the HOSTNAME). But this is also not true for System.Diagnostics.Activity.Id.

I suggest that you change to this instead:

 [LayoutRenderer("ark.activityid")] 
 [ThreadSafe] 
 public class ActivityIdLayoutRenderer : LayoutRenderer 

Also notice that NLog.DiagnosticSource is available, but that will ofcourse be another dependency, that might be unwanted.

Can see that you have been working on implementing helper-methods to make it easier to setup NLog Targets (File + Console + Mail + Database) from code. NLog 5.0 introduces something similar out-of-the-box. Would be grateful if you could take a peek at the current prototype, and give input whether it matches your expectations.

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.