小编Geo*_*ong的帖子

如何从C#控制台应用程序写入Azure WebJobs中的日志?

我正在测试Azure Webjobs.我编写了一个控制台应用程序,它轮询SQL数据库以获取新工作并对其进行处理.我没有使用WebJobs SDK,因为它只支持Azure存储.

我上传作业,它运行,然后失败,但有一个例外,说它无法连接到SQL数据库实例.我想知道正在使用什么连接字符串; 是从Azure网站获取连接字符串.日志给我这个:

[03/14/2014 22:24:25 > 512206: SYS INFO] Status changed to Running
[03/14/2014 22:24:40 > 512206: ERR ] 
[03/14/2014 22:24:40 > 512206: ERR ] Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, …
Run Code Online (Sandbox Code Playgroud)

azure-webjobs

50
推荐指数
2
解决办法
3万
查看次数

Azure WebJobs的优雅关闭

我打算使用连续的Azure WebJob来发送电子邮件和推送通知.我知道WebJobs会因各种原因不时启动和停止.这没关系,但我希望有机会在工作关闭前"清理".

这样我的WebJob就可以更新数据库记录的状态或删除每个批处理中已处理的队列项,这样下次作业运行时就不会发送重复的消息.

作为一个黑暗的镜头,我尝试将以下代码添加到我的C#控制台应用程序:

Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) =>
{
  e.Cancel = true;
  program.keepRunning = false;
};
Run Code Online (Sandbox Code Playgroud)

然后我使用keepRunning bool来控制main while循环,并在while循环之外放置一个Console.Writeline("Exited Gracefully").但这似乎没有帮助.当我告诉作业停止时(使用我的Azure网站的Webjobs选项卡中的停止按钮),作业从列表中消失,并显示"无法停止作业:'JobName'." 在Azure门户中(位于页面底部).我没有看到WebJob日志中的"Exited Gracefully"文本.所以我把那个代码拿出来,因为它没有帮助.

所以,我正在寻找一个好方法,让我的WebJob被通知其秒数已经编号,并且需要按顺序获取其事务.

azure-webjobs

6
推荐指数
1
解决办法
5580
查看次数

标签 统计

azure-webjobs ×2