Azure WebJob 配置是否用于控制日志记录?
Is ther an Azure WebJob Configuration to control logging?
我正在试验 WebJobs。我在 Visual Studio 2015 年创建了一个新的 WebJob 项目。这是代码:
public class Program
{
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
public static void Main()
{
JobHostConfiguration config = new JobHostConfiguration();
config.Tracing.ConsoleLevel = TraceLevel.Info;
Environment.SetEnvironmentVariable("AzureWebJobsEnv", "Development");
if(config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
config.UseTimers();
JobHost host = new JobHost(config);
host.RunAndBlock();
}
}
public class Functions
{
public static void GetMarketData([TimerTrigger("00:00:01")] TimerInfo timer, TextWriter log)
{
//log.WriteLine($"Market data retrieved at {DateTime.Now.ToString("yyMMdd HH:mm:ss")}");
}
}
如您所见,我正在使用 Timers 扩展,以便每隔一秒调用一次该函数。
当我在本地 运行 执行此操作时(假设也在 Azure 上),即使我在函数中注释掉了 log.WriteLine,也会在我创建的存储帐户上创建日志。有文件显示为空文本的输出日志,有包含函数相关信息的主机日志。
假设每秒钟都有一个日志。我怎样才能阻止这些日志被写入?
请尝试将仪表板连接字符串设置为空,如下例所示,以禁用日志记录。
var config = new JobHostConfiguration();
config.DashboardConnectionString = "";
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
我正在试验 WebJobs。我在 Visual Studio 2015 年创建了一个新的 WebJob 项目。这是代码:
public class Program
{
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
public static void Main()
{
JobHostConfiguration config = new JobHostConfiguration();
config.Tracing.ConsoleLevel = TraceLevel.Info;
Environment.SetEnvironmentVariable("AzureWebJobsEnv", "Development");
if(config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
config.UseTimers();
JobHost host = new JobHost(config);
host.RunAndBlock();
}
}
public class Functions
{
public static void GetMarketData([TimerTrigger("00:00:01")] TimerInfo timer, TextWriter log)
{
//log.WriteLine($"Market data retrieved at {DateTime.Now.ToString("yyMMdd HH:mm:ss")}");
}
}
如您所见,我正在使用 Timers 扩展,以便每隔一秒调用一次该函数。
当我在本地 运行 执行此操作时(假设也在 Azure 上),即使我在函数中注释掉了 log.WriteLine,也会在我创建的存储帐户上创建日志。有文件显示为空文本的输出日志,有包含函数相关信息的主机日志。
假设每秒钟都有一个日志。我怎样才能阻止这些日志被写入?
请尝试将仪表板连接字符串设置为空,如下例所示,以禁用日志记录。
var config = new JobHostConfiguration();
config.DashboardConnectionString = "";
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();