Serilog Azure WebJobs/Functions TraceWriter Sink
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/Serilog.Sinks.AzureWebJobsTraceWriter Updated Microsoft.Azure.WebJobs version to 2.1-beta1 Aug 14, 2017
tests/Serilog.Sinks.AzureWebJobsTraceWriter.UnitTests
.gitignore
CodeCoverage.runsettings Updated test script logic. Jun 16, 2017
LICENSE
Serilog.Sinks.AzureWebJobsTraceWriter.sln
appveyor.yml Rotated coverall token and added some debug information for AppVeyor. Jun 16, 2017
readme.md
test.ps1

readme.md

Serilog Azure WebJobs/Functions TraceWriter Sink

NuGet Version AppVeyor Coverage Status

A Serilog sink that writes events to Azure WebJob Host's TraceWriter. This is the logging mechanism used by both Azure WebJob's, and Azure Functions (which is built on top of the WebJob Host).

Getting started

Install the Serilog.Sinks.AzureWebJobsTraceWriter package from NuGet.

Within your logger configuration, you can now include a TraceWriter as a sink:

using Serilog.Sinks.AzureWebJobsTraceWriter;

ILogger log = new LoggerConfiguration()
    .WriteTo.TraceWriter(traceWriter)
    .CreateLogger();
    
log.Warning("This will be written to the TraceWriter");

Azure Functions Example

You will need to include the required Nuget packages within the functions project.json:

{
    "frameworks": {
        "net46": {
            "dependencies": {
                "Serilog": "2.4.0",
                "Serilog.Sinks.AzureWebJobsTraceWriter": "1.0.0",
                "Microsoft.Azure.WebJobs": "2.1.0"
            }
        }
    }
}

Then you can create a new logger within the scope of your function's static run method:

// This is required to point to the internal version of WebJobs.Host
#r "Microsoft.Azure.WebJobs.Host"

using System.Net;
using Serilog;
using Serilog.Sinks.AzureWebJobsTraceWriter;

public static string Run(HttpRequestMessage req, TraceWriter log)
{
    using (Logger logger = new LoggerConfiguration()
                        .WriteTo.TraceWriter(log)
                        .CreateLogger())
    {

        string someData = Guid.NewGuid().ToString();

        logger.Information("This is logging test for {someData}", someData);

        return $"Done with {someData}"; 
    }
} 

Helpful Links