当我在Windows Azure中作为WebJob运行控制台应用程序时,在几行日志之后,它会添加一个警告:
[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日志?
发布于 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/
发布于 2016-07-28 00:44:55
您还可以潜在地使用自定义TraceWriter。
示例:https://gist.github.com/aaronhoffman/3e319cf519eb8bf76c8f3e4fa6f1b4ae
JobHost
配置
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实现
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);
}
}
https://stackoverflow.com/questions/23491907
复制相似问题