Azure how to enable full WebJob logs Azure how to enable full WebJob logs azure azure

Azure how to enable full WebJob logs


The way to enable full (continuous) WebJobs logs is actually in the error message: enable website application diagnostics, you can do this via the Azure portal on the website's CONFIGURE tab, you can set the application logs to go to either the file-system (but only for 12 hours), table storage or blob storage.

Once enabled the full logs for WebJobs will go on the selected storage.

More info on application diagnostics for Azure websites: http://azure.microsoft.com/en-us/documentation/articles/web-sites-enable-diagnostic-log/


You could also potentially use a custom TraceWriter.

Example: https://gist.github.com/aaronhoffman/3e319cf519eb8bf76c8f3e4fa6f1b4ae

JobHost config

static void Main(){    var config = new JobHostConfiguration();    // Log Console.Out to SQL using custom TraceWriter    // Note: Need to update default Microsoft.Azure.WebJobs package for config.Tracing.Tracers to be exposed/available    config.Tracing.Tracers.Add(new SqlTraceWriter(        TraceLevel.Info,        "{{SqlConnectionString}}",        "{{LogTableName}}"));    var host = new JobHost(config);    host.RunAndBlock();}

Sample SqlTraceWriter implementation

public class SqlTraceWriter : TraceWriter{    private string SqlConnectionString { get; set; }    private string LogTableName { get; set; }    public SqlTraceWriter(TraceLevel level, string sqlConnectionString, string logTableName)        : base(level)    {        this.SqlConnectionString = sqlConnectionString;        this.LogTableName = logTableName;    }    public override void Trace(TraceEvent traceEvent)    {        using (var sqlConnection = this.CreateConnection())        {            sqlConnection.Open();            using (var cmd = new SqlCommand(string.Format("insert into {0} ([Source], [Timestamp], [Level], [Message], [Exception], [Properties]) values (@Source, @Timestamp, @Level, @Message, @Exception, @Properties)", this.LogTableName), sqlConnection))            {                cmd.Parameters.AddWithValue("Source", traceEvent.Source ?? "");                cmd.Parameters.AddWithValue("Timestamp", traceEvent.Timestamp);                cmd.Parameters.AddWithValue("Level", traceEvent.Level.ToString());                cmd.Parameters.AddWithValue("Message", traceEvent.Message ?? "");                cmd.Parameters.AddWithValue("Exception", traceEvent.Exception?.ToString() ?? "");                cmd.Parameters.AddWithValue("Properties", string.Join("; ", traceEvent.Properties.Select(x => x.Key + ", " + x.Value?.ToString()).ToList()) ?? "");                cmd.ExecuteNonQuery();            }        }    }    private SqlConnection CreateConnection()    {        return new SqlConnection(this.SqlConnectionString);    }}