我正在测试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, error: 26 - Error Locating Server/Instance Specified)
我想将数据写入这些日志(例如正在使用的连接字符串是什么)。我尝试了Console.WriteLine,Debug.WriteLine,Console.Error.WriteLine。它们都没有显示在我的WebJob日志中。
显然,我可以通过在显示我想要的消息文本时引发异常来获取数据,但是必须有更好的方法!如何将SYS INFO行和ERR行写入日志?
关于日志:
对于连续的 Web作业-Console.Out和Console.Error路由到“应用程序日志”,它们将显示为文件,blob或表存储,具体取决于您对应用程序日志的配置(类似于您的网站)。
同样,每次调用的前100行也将转到WebJob日志文件(以减轻启动时WebJob失败时的调试痛苦),该文件可使用Azure门户访问(但也保存在站点的文件系统上,位于data / jobs / continuous / jobName上) )。
对于触发/计划的 WebJobs-Console.Out / Console.Error被路由到特定于WebJobs的运行日志文件,该文件也可以使用Azure门户进行访问,并存储在data / jobs / triggered / jobName / runId中。
Console.Out被视为(标记为)INFO,而Console.Error被视为ERROR。
关于连接字符串:
您可以使用ConfigurationManager类访问与网站中相同的连接字符串,对于不是用.NET编写的WebJob,您可以找到这些连接字符串(和应用程序设置)作为环境变量(与您的网站相同)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句