While the above are correct you can also create your own custom TraceWriter instance that intercepts Trace calls in your application.
Example of a TraceWriter class:
using System.Diagnostics;
using Microsoft.Azure.WebJobs.Host;
namespace MiscOperations
{
/// <summary>
/// Custom <see cref="TraceWriter"/> demonstrating how JobHost logs/traces can
/// be intercepted by user code.
/// </summary>
public class CustomTraceWriter : TraceWriter
{
public CustomTraceWriter(TraceLevel level)
: base(level)
{
}
public override void Trace(TraceEvent traceEvent)
{
// handle trace messages here
}
}
}
Then in your JobHostConfuration setup you register your instance of the TraceWriter class in the main method of the console application. I.e in Program.cs.
JobHostConfiguration config = new JobHostConfiguration()
{
NameResolver = new ConfigNameResolver(),
};
// Demonstrates how the console trace level can be customized
config.Tracing.ConsoleLevel = TraceLevel.Verbose;
// Demonstrates how a custom TraceWriter can be plugged into the
// host to capture all logging/traces.
config.Tracing.Tracers.Add(new CustomTraceWriter(TraceLevel.Info));
JobHost host = new JobHost(config);
host.RunAndBlock();
This way you can do other things with the trace such as write to an external service or create alerts.
Taken from the Azure SKD Samples Gitthub
CustomTraceWriter.cs
Program.cs