Nodinite.Serilog.AzureBlobStorageSink 2.0.22

There is a newer version of this package available.
See the version list below for details.
dotnet add package Nodinite.Serilog.AzureBlobStorageSink --version 2.0.22
                    
NuGet\Install-Package Nodinite.Serilog.AzureBlobStorageSink -Version 2.0.22
                    
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.AzureBlobStorageSink" Version="2.0.22" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nodinite.Serilog.AzureBlobStorageSink" Version="2.0.22" />
                    
Directory.Packages.props
<PackageReference Include="Nodinite.Serilog.AzureBlobStorageSink" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nodinite.Serilog.AzureBlobStorageSink --version 2.0.22
                    
#r "nuget: Nodinite.Serilog.AzureBlobStorageSink, 2.0.22"
                    
#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.
#:package Nodinite.Serilog.AzureBlobStorageSink@2.0.22
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nodinite.Serilog.AzureBlobStorageSink&version=2.0.22
                    
Install as a Cake Addin
#tool nuget:?package=Nodinite.Serilog.AzureBlobStorageSink&version=2.0.22
                    
Install as a Cake Tool

Nodinite.Serilog.AzureBlobStorageSink

Nodinite.Serilog.AzureBlobStorageSink 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 Azure Storage Account; 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 a Container in an Azure Storage Account.
  • Seamless Integration: Works well with existing Serilog configurations.
  • Customizable: Supports additional custom fields to send along with the log events (CONTEXT PROPERTIES).
  • Large messaging support.
  • Use either Managed Identity, or a ConnectionString

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.AzureBlobStorageSink.Tests" Name of Endpoint transport
EndPointUri "Nodinite.Serilog.AzureBlobStorageSink.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

Use the code snippets below to get started. This configuration log events to the specified Container in the Azure Storage Account.

This example assumes you are using the connection string based approach.

var connectionString = "{Your Azure Storage Account Connection String";

var settings = new NodiniteLogEventSettings()
{
    LogAgentValueId = 503,
    EndPointDirection = 0,
    EndPointTypeId = 0,
    EndPointUri = "Nodinite.Serilog.AzureBlobStorageSink.Tests.Serilog",
    EndPointName = "Nodinite.Serilog.AzureBlobStorageSink.Tests",
    ProcessingUser = "NODINITE",
    ProcessName = "Nodinite.Serilog.AzureBlobStorageSink.Tests",
    ProcessingMachineName = "NODINITE-DEV",
    ProcessingModuleName = "DOTNETCORE.TESTS",
    ProcessingModuleType = "DOTNETCORE.TESTPROJECT"
};

ILogger log = new LoggerConfiguration()
    .WriteTo.NodiniteAzureBlobStorageSink(connectionString, settings)
    .CreateLogger()
    .ForContext("ApplicationInterchangeId", $"CustomId-{Guid.NewGuid().ToString()}")
    .ForContext("Body", JsonConvert.SerializeObject(new { Id = 1 }))
    .ForContext("OriginalMessageType", "TestMessage#1.0");

Using Appsettings.json (Preferred)

Besides Serilog, the following nuget packages need to be installed

Using the following code to initialize the logger in your application:

var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();

Logger log = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    .CreateLogger();

If you opt for a ConnectionString based approach, use the following example and use it in your appsettings.json:

{
  "Serilog": {
    "Using": [ "Nodinite.Serilog.AzureBlobStorageSink" ],
    "WriteTo": [
      {
        "Name": "NodiniteAzureBlobStorageSinkWithConnectionString",
        "Args": {
          "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=acme;AccountKey=xyz;EndpointSuffix=core.windows.net",
          "ContainerName": "logevents",
          "Settings": {
            "LogAgentValueId": 503,
            "EndPointName": "Nodinite.Serilog.AzureBlobStorageSink.Tests",
            "EndPointUri": "Nodinite.Serilog.AzureBlobStorageSink.Tests.Serilog",
            "EndPointDirection": 0,
            "EndPointTypeId": 0,
            "OriginalMessageTypeName": "Serilog.LogEvent",
            "ProcessingUser": "NODINITE",
            "ProcessName": "Nodinite.Serilog.AzureBlobStorageSink.Tests",
            "ProcessingMachineName": "NODINITE-DEV",
            "ProcessingModuleName": "DOTNETCORE.TESTS",
            "ProcessingModuleType": "DOTNETCORE.TESTPROJECT"
          }
        }
      }
    ]
  }
}

If you opt for a Managed Identity based approach, use the following example and use it in your appsettings.json:

NOTE: There is a different value in the Name for this configuration compared to the ConnectionString based example.

{
  "Serilog": {
    "Using": [ "Nodinite.Serilog.AzureBlobStorageSink" ],
    "WriteTo": [
      {
        "Name": "NodiniteAzureBlobStorageSink",
        "Args": {
          "StorageAccountName": "acme",
          "ContainerName": "logevents",
          "Settings": {
            "LogAgentValueId": 503,
            "EndPointName": "Nodinite.Serilog.AzureBlobStorageSink.Tests",
            "EndPointUri": "Nodinite.Serilog.AzureBlobStorageSink.Tests.Serilog",
            "EndPointDirection": 0,
            "EndPointTypeId": 0,
            "OriginalMessageTypeName": "Serilog.LogEvent",
            "ProcessingUser": "NODINITE",
            "ProcessName": "Nodinite.Serilog.AzureBlobStorageSink.Tests",
            "ProcessingMachineName": "NODINITE-DEV",
            "ProcessingModuleName": "DOTNETCORE.TESTS",
            "ProcessingModuleType": "DOTNETCORE.TESTPROJECT"
          }
        }
      }
    ]
  }
}

Logging Context Properties

The version should be properly updated when you update the NuGet packages. All versions below are only an example. Make sure to timely update to the latest.

    <ItemGroup>
      <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.2" />
      <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.0.0" />
      <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
      <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
      <PackageReference Include="Nodinite.Serilog.AzureBlobStorageSink" Version="2.0.13" />
      <PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
  </ItemGroup>

Startup file (Program.cs)

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.AzureBlobStorageSink"],
    "WriteTo": [
      {
        "Name": "AzureBlobStorageSink",
        "Args": {
          "StorageAccountName": "acme",
          "ContainerName": "logevents",
          "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)

Copy the ConnectionString from the Azure Portal (Access keys) for the Storage Account in use.

{
  "Serilog": {
    "Using": [ "Nodinite.Serilog.AzureBlobStorageSink" ],
    "WriteTo": [
      {
        "Name": "AzureBlobStorageSinkWithConnectionString",
        "Args": {
          "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=acme;AccountKey=xyz;EndpointSuffix=core.windows.net",
          "ContainerName": "logevents",
          "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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.38 146 7/10/2025
2.0.36 270 5/16/2025
2.0.35 283 4/9/2025
2.0.29 259 4/1/2025
2.0.28 408 3/11/2025
2.0.27 310 2/24/2025
2.0.26 234 2/12/2025
2.0.25 138 1/27/2025
2.0.24 93 1/15/2025
2.0.23 210 1/14/2025
2.0.22 117 1/10/2025
2.0.21 97 1/8/2025
2.0.20 1,683 12/11/2024
2.0.19 113 11/15/2024
2.0.18 182 10/25/2024
2.0.17 118 10/10/2024
2.0.16 197 9/11/2024
2.0.15 143 8/23/2024
2.0.14 171 7/26/2024