Nodinite.Serilog.EventHubSink 2.0.16

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

// Install Nodinite.Serilog.EventHubSink as a Cake Tool
#tool nuget:?package=Nodinite.Serilog.EventHubSink&version=2.0.16                

Nodinite.Serilog.EventHubSink

Nodinite.Serilog.EventHubSink is a custom built Serilog sink. Unlike the default Serilog sinks that write logs to a file, database, or other conventional destinations, this sink creates Nodinite log events and send them to an Event Hub Entity; These are later picked up by the Nodinite Pickup Service for further routing into a Nodinite instance.

Features

  • Real-time logging: Events are sent to Microsoft Azure Event Hub.
  • Seamless Integration: Works well with existing Serilog configurations.
  • Customizable: Supports additional custom fields to send along with the log events (CONTEXT PROPERTIES).
  • Max message size is 1024 KB

Documentation

Nodinite - Docs
Nodinite - Serilog Docs

Configuration

A Nodinite Log Event has mandatory and optional fields. Below is an example to get you started.

Field Example Value Comment
LogAgentValueId 503 Who (Log Agents) sent the data
EndPointName "Nodinite.Serilog.EventHubSink.Tests" Name of Endpoint transport
EndPointUri "Nodinite.Serilog.EventHubSink.Tests.Serilog" URI for Endpoint transport
EndPointDirection 0 Direction for Endpoint transport
EndPointTypeId 0 Type of Endpoint transport
OriginalMessageTypeName "Serilog.LogEvent" Message Type Name
ProcessingUser "Nodinite" Log Identity
ProcessName "My customer import process" Name of process
ProcessingMachineName "localhost" Name of server where log event originated
ProcessingModuleName "INT101-HelloHappyCustomers-Application" Name of module
ProcessingModuleType "FileImport" Type of module, exe, dll, service

Using code

Besides Serilog, the following nuget packages need to be installed in your project

Use the code snippets below to get started. This configuration log events to the specified Event Hub in the Event Hub Namespace.

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Core;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices((context, services) =>
    {
        // Create configuration object and read settings
        var configuration = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json")
            .Build();

        // Create the logger object 
        var logger = new LoggerConfiguration()
            .ReadFrom.Configuration(configuration)
            .CreateLogger();

        // Register the logger object as a singleton using dependency injection to achieve great performance when you write multiple logs
        services.AddSingleton<Serilog.ILogger, Serilog.Core.Logger>(sp => logger);
    })
    .Build();

host.Run();

Log (Function.cs)

Inject the Logger inside the constructor instead on the method level.

using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using Serilog.Core.Enrichers;

namespace Nodinite.Demo.Azure.Functions
{
    public class Function1
    {
        private readonly Serilog.ILogger _logger;

        public Function1(Serilog.ILogger logger)
        {
            _logger = logger;
        }

        [Function("Function1")]
        public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
        {

            #region Nodinite Serilog sample code (should be refactored into a reusable component injected using dependency injection; all part of your documented asynchronous Logging Strategy)
            
            string payload = await new StreamReader(req.Body).ReadToEndAsync();
            string correlationId = Guid.NewGuid().ToString();
            
            if (req.Headers.TryGetValue("x-ms-client-tracking-id", out Microsoft.Extensions.Primitives.StringValues id))
            {
                correlationId = id[0];
            }
        
            _logger.ForContext(new PropertyEnricher("ApplicationInterchangeId", $"{correlationId}"))
              .Enrich.WithProperty("Color", "Yellow")
              .ForContext(new PropertyEnricher("Body", JsonConvert.SerializeObject(payload)))
              .ForContext(new PropertyEnricher("OriginalMessageType", "OrderMessage#1.0"))
              .Information("Hello from Function");
            
            #endregion

            var response = req.CreateResponse(HttpStatusCode.OK);
            response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
            response.WriteString("Welcome to Azure Functions!");

            return response;
        }
    }
}

appsettings.json (Using Managed Identity)

{
  "Serilog": {
    "Using": ["Nodinite.Serilog.EventHubSink"],
    "WriteTo": [
      {
        "Name": "NodiniteEventHubSink",
        "Args": {
          "eventHubNameSpace": "acme.servicebus.windows.net",
          "eventHubName": "eventhub-01",
          "Settings": {
            "LogAgentValueId": 503,
            "EndPointName": "Nodinite.Serilog.Sink.Tests",
            "EndPointUri": "Nodinite.Serilog.Sink.Tests.Serilog",
            "EndPointDirection": 0,
            "EndPointTypeId": 0,
            "OriginalMessageTypeName": "Serilog.LogEvent",
            "ProcessingUser": "NODINITE",
            "ProcessName": "Nodinite.Serilog.Sink.Tests",
            "ProcessingMachineName": "NODINITE-DEV",
            "ProcessingModuleName": "DOTNETCORE.TESTS",
            "ProcessingModuleType": "DOTNETCORE.TESTPROJECT"
          }
        }
      }
    ]
  }
}

appsettings.json (Using a Connection string)

Use a dedicated Shared access policy to create a connectionstring including the EntityPath=%name%.

{
  "Serilog": {
    "Using": [ "Nodinite.Serilog.EventHubSink" ],
    "WriteTo": [
      {
        "Name": "NodiniteEventHubSink",
        "Args": {
          "ConnectionString": "Endpoint=sb://xyz.servicebus.windows.net/;SharedAccessKeyName=Default;SharedAccessKey=secretstuff;EntityPath=yourentityname
",
          "Settings": {
            "LogAgentValueId": 503,
            "EndPointName": "Nodinite.Serilog.Sink.Tests",
            "EndPointUri": "Nodinite.Serilog.Sink.Tests.Serilog",
            "EndPointDirection": 0,
            "EndPointTypeId": 0,
            "OriginalMessageTypeName": "Serilog.LogEvent",
            "ProcessingUser": "NODINITE",
            "ProcessName": "Nodinite.Serilog.Sink.Tests",
            "ProcessingMachineName": "NODINITE-DEV",
            "ProcessingModuleName": "DOTNETCORE.TESTS",
            "ProcessingModuleType": "DOTNETCORE.TESTPROJECT"
          }
        }
      }
    ]
  }
}

Support

For bugs, feature requests, or other concerns, please contact us at support@nodinite.com.

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.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.16 111 9/11/2024
2.0.15 268 8/23/2024
2.0.14 395 7/26/2024
2.0.12 99 7/10/2024
2.0.11 107 6/12/2024
2.0.9 77 5/15/2024
2.0.8 376 4/10/2024
2.0.7 155 3/13/2024
2.0.6 839 2/14/2024
2.0.4 599 1/10/2024
2.0.2 339 11/15/2023
2.0.1 290 11/6/2023
2.0.0 3,858 2/13/2023
1.4.0 260 2/9/2023
1.3.0 2,187 2/21/2022
1.2.0 454 2/14/2022
1.0.1 638 5/4/2020
1.0.0 568 2/28/2020