Coder Social home page Coder Social logo

dallasbeek / serilog-sinks-newrelic-logs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thiagobarradas/serilog-sinks-newrelic-logs

0.0 0.0 0.0 36 KB

A Serilog sink that writes events to the NewRelic Logs.

Home Page: https://www.nuget.org/packages/Serilog.Sinks.NewRelic.Logs

License: Other

C# 100.00%

serilog-sinks-newrelic-logs's Introduction

Build Status NuGet Downloads NuGet Version Quality Gate Status

A Serilog sink that writes events to the NewRelic Logs.

Getting started

Log.Logger = new LoggerConfiguration()
    .WriteTo.NewRelicLogs(
        endpointUrl: "https://log-api.newrelic.com/log/v1", 
        applicationName: "Serilog.Sinks.NewRelic.Sample", 
        licenseKey: "[Your API key]")
    .CreateLogger();

If you have new relic agent and use environment variables NEW_RELIC_APP_NAME and NEW_RELIC_LICENSE_KEY, you can do just:

Log.Logger = new LoggerConfiguration()
    .WriteTo.NewRelicLogs()
    .CreateLogger();

The available parameters are:

  • applicationName of the current application in NewRelic If the parameter is omitted, then the value of the "NewRelic.AppName" appSetting will be used.
  • endpointUrl is the ingestion URL of NewRelic Logs. The US endpoint is used by default if this value is omitted.
  • licenseKey is the NewRelic License key, which is also used with the NewRelic Agent.
  • insertKey is New Relic Insert API key. Either licenseKey or insertKey must be supplied.

The events are submitted to NewRelic Logs in batches, and the sink is derived from PeriodicBatchingSink. It therefore supports the following parameter:

  • batchSizeLimit is the maximum number of events to include in a single batch. Default is 1000 entries
  • period is the time to wait between checking for event batches. It is TimeSpan with a default value of 2 seconds. If provided from AppSettings, the value should be given as an absolute time span, i.e.: "0.00:00:05" standing for 5 seconds.

The batches are formatted using NewRelic Logs detailed JSON body and are transmitted GZip-compressed.

All properties along with the rendered message will be emitted to NewRelic Logs. This sink adds four additional properties:

  • timestamp in milliseconds since epoch
  • application holds the value from applicationName
  • level is the actual log level of the event.
  • stack_trace holds the stack trace portion of an exception.
  • exception holds the .toString() of an exception.

If newrelic.linkingmetadata property is present in an event, it will be unrolled into individual NewRelic properties used for "logs in context".

Install via NuGet

PM> Install-Package Serilog.Sinks.NewRelic.Logs

JSON configuration

It is possible to configure the sink using Serilog.Settings.Configuration by specifying the license key and other desired parameters in appsettings.json:

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.NewRelic.Logs" ],
    "WriteTo": [
      {
        "Name": "NewRelicLogs",
        "Args": {
          "applicationName": "NewRelicLogTestSample",
          "licenseKey": "58e9892abd3f09d91b0db0d0e9e95628FFFFNRAL"
          //... other parameters
        }
      }
    ],
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId", "WithNewRelicLogsInContext" ]
  }
}

Contributors

This code is based on https://github.com/stanisls/serilog-sinks-newreliclogs

Thanks @stanisls and @johnkattenhorn ๐Ÿ’ช

How can I contribute?

Please, refer to CONTRIBUTING

Found something strange or need a new feature?

Open a new Issue following our issue template ISSUE_TEMPLATE

Changelog

See in nuget version history

Did you like it? Please, make a donate :)

if you liked this project, please make a contribution and help to keep this and other initiatives, send me some Satochis.

BTC Wallet: 1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX

1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX

serilog-sinks-newrelic-logs's People

Contributors

thiagobarradas avatar georgechond94 avatar gorkemhacioglu 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.