1

I'm using the following code to try out Serilog and the DocumentDB sink. I see the Database (Diagnostics) and Collection (Logs) created but I don't see any documents in Azure portal's DocumentExplorer.

Here's the code.

class Program
{
    static void Main(string[] args)
    {
        Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));

        var Logger = new LoggerConfiguration()
            .MinimumLevel.Verbose()
            .WriteTo.Console()
            .WriteTo.AzureDocumentDB("https://<blankedout>.documents.azure.com:443/", "some key", timeToLive: 7)
            .CreateLogger();
        Logger.Verbose("Verbose");
        Logger.Debug("Debug");
        Logger.Information("DirectTest");
        Logger.Error("BADFOOD!");
    }
}

This is C# console app probject targeted to .NET 4.6 using VS2015. Nuget versions are:

Microsoft.Azure.DocumentDB 1.13.1 Serilog 2.4.0 Serilog.Sinks.AzureDocumentDB 3.6.1 Serilog.Sinks.Console 2.1.0

Debug Output contains the following from DocDBTrace:

DocDBTrace Information: 0 : DocumentClient with id 1 initialized at endpoint: https://.documents.azure.com/ with ConnectionMode: Gateway, connection Protocol: Https, and consistency level: null 2017-04-13T17:30:51.8553244Z Opening database Diagnostics

DocDBTrace Information: 0 : RefreshLocationAsync() refreshing locations

DocDBTrace Information: 0 : Set WriteEndpoint https://-westus2.documents.azure.com/ ReadEndpoint https://-westus2.documents.azure.com/

Serilog.Sinks.AzureDocumentDB.Sinks.AzureDocumentDb.bulkImport.js

DocDBTrace Information: 0 : DocumentClient with id 1 disposed.*

Tom W
  • 11
  • 1

1 Answers1

0

The sink is asynchronous. You need to call Log.CloseAndFlush() before your application exits to ensure the documents are written before the process exits:

using (var logger = new LoggerConfiguration()
    .MinimumLevel.Verbose()
    .WriteTo.Console()
    .WriteTo.AzureDocumentDB("https://<blankedout>.documents.azure.com:443/", "some key", timeToLive: 7)
    .CreateLogger())
{
    logger.Verbose("Verbose");
    logger.Debug("Debug");
    logger.Information("DirectTest");
    logger.Error("BADFOOD!");
}
Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101