首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Azure如何启用完整的WebJob日志

Azure如何启用完整的WebJob日志
EN

Stack Overflow用户
提问于 2014-05-06 18:16:29
回答 2查看 17.5K关注 0票数 26

当我在Windows Azure中作为WebJob运行控制台应用程序时,在几行日志之后,它会添加一个警告:

代码语言:javascript
复制
[05/06/2014 09:42:40 > 21026c: WARN] Reached maximum allowed output lines for this run, to see all of the job's logs you can enable website application diagnostics

并停止记录。我正在使用BASIC托管计划检查我的网站中的所有设置,但我无法找到任何可以解决此问题的方法。

如何启用完整的webJob日志?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-07 00:39:24

启用完整(连续) WebJobs日志的方法实际上在错误消息中:enable website application diagnostics,你可以通过网站的配置选项卡上的Azure门户执行此操作,你可以将应用程序日志设置为转到文件系统(但只有12小时)、表存储或blob存储。

启用后,WebJobs的完整日志将放在选定的存储上。

有关Azure网站的应用程序诊断的更多信息:http://azure.microsoft.com/en-us/documentation/articles/web-sites-enable-diagnostic-log/

票数 25
EN

Stack Overflow用户

发布于 2016-07-28 00:44:55

您还可以潜在地使用自定义TraceWriter。

示例:https://gist.github.com/aaronhoffman/3e319cf519eb8bf76c8f3e4fa6f1b4ae

JobHost配置

代码语言:javascript
复制
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();
}

示例SqlTraceWriter实现

代码语言:javascript
复制
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);
    }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23491907

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档