Skip to content

Add Configurable Encoding Support for Azure Blob Storage Sink (Default: UTF-8 without BOM) #129

@arthur-leite

Description

@arthur-leite

The serilog-sinks-azureblobstorage sink currently does not provide an option to configure the text encoding for logs exported to Azure Blob Storage. This can lead to issues when logs need to be processed by systems expecting a specific encoding, such as UTF-8 without BOM (Byte Order Mark).

The serilog-sinks-file sink already supports configurable encoding, with UTF-8 without BOM as the default, as implemented in the FileSink class (reference). A similar feature for the Azure Blob Storage sink would improve consistency across Serilog sinks and enhance compatibility with various log processing tools.

Proposed Solution

Add an optional encoding parameter to the Azure Blob Storage sink configuration, with the default set to UTF-8 without BOM (e.g., System.Text.Encoding.UTF8). This would allow users to specify alternative encodings if needed, such as UTF-8 with BOM or other encodings supported by System.Text.Encoding.

Example Configuration

Log.Logger = new LoggerConfiguration()
    .WriteTo.AzureBlobStorage(
                    connectionString: storageConnectionString,
                    storageContainerName: "logs",
                    storageFileName: "api-{yyyyMMdd}.log",
                    period: TimeSpan.FromSeconds(30),
                    batchPostingLimit: 10,
                    encoding: System.Text.Encoding.UTF8 // Default, no BOM
    )
    .CreateLogger();

Benefits

  • Consistency with the serilog-sinks-file sink's encoding support.
  • Improved compatibility with log processing tools that require specific encodings.
  • Greater flexibility for users with diverse encoding requirements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions