This is an example of an Azure Function that listens to the logging queue setup in the Nexus configuration.
using System;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Nexus.Link.Libraries.Core.Logging;
namespace Sandbox.NexusFunctions
{
public static class NexusLogging
{
[FunctionName("NexusLogging")]
public static async Task Run([QueueTrigger("logging-queue", Connection = "AzureWebJobsStorage")] string logItem, ILogger log)
{
try
{
var logRecord = JsonConvert.DeserializeObject<LogRecord>(logItem);
await HandleLogRecord(logRecord, log);
}
catch (Exception e)
{
log.LogError("Failed to handle log record." +
" Logging queue item as Information below.", e);
log.LogInformation(logItem);
}
}
private static async Task HandleLogRecord(LogRecord logRecord, ILogger log)
{
// Note! In the real jungle, we would send this to this to Application Insights, Splunk, Stackify, Kibana, etc.
// Now we just pretty print it.
log.LogInformation(JsonConvert.SerializeObject(logRecord, Formatting.Indented));
await Task.Yield();
}
}
}
You get access to the Nexus Link libraries by e.g. using a Nuget.config file like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<apikeys></apikeys>
<packageSources>
<add key="Nexus Libraries" value="http://fulcrum-nuget.azurewebsites.net/nuget" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>