[英]logging on Azure
How can we log on Azure withe the granularity & control equivalent to log4net? 我们如何使用与log4net等效的粒度和控制来登录Azure? We use log4net in our web apps we run on IIS and that works very well for us. 我们在IIS上运行的网络应用程序中使用log4net,这对我们非常有用。 Is that the best on Azure too? 这也是Azure上最好的吗?
We absolutely prefer log files ( as opposed to database entries ) but if there's something that works better in Azure, I'm open to improvements. 我们绝对更喜欢日志文件( 而不是数据库条目 ),但是如果在Azure中有更好的效果,我会接受改进。 The way Trace writes to a table in Azure is horrible - we definitely don't wan that. Trace写入Azure中的表格的方式非常糟糕 - 我们绝对不会这样做。
The reason I prefer log files is it's super easy to see what happened in sequence which is what I need 99% of the time. 我更喜欢日志文件的原因是它很容易看到顺序发生了什么,这是我99%的时间所需要的。
This is for an Azure web app that will have multiple instances. 这适用于具有多个实例的Azure Web应用程序。 It's fine if the logs are distinct to each instance. 如果日志与每个实例不同,那就没问题。
thanks - dave 谢谢 - 戴夫
This is pretty straight forward. 这很简单。 I use the following log4net
configuration to dump a log file in the web application root folder (easily changed to a sub-folder): 我使用以下log4net
配置将日志文件转储到Web应用程序根文件夹中(轻松更改为子文件夹):
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="my_web.log" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%date{yyyy-dd-MM HH:mm:ss.fff} [%thread] %-5level %logger.%method [%property{NDC}] - %message%newline" />
</layout>
</appender>
</log4net>
I then inspect the log file when needed directly from Visual Studio (double clicking the file downloads it) Server Explorer: 然后我直接从Visual Studio检查日志文件(双击文件下载它)服务器资源管理器:
I think you should be careful when storing the log file locally in Azure as this is not garanteed to stick around. 我认为在Azure中本地存储日志文件时应该小心,因为这不能保证坚持下去。 The VM used to store the website can be reimaged and the logs will be lost. 用于存储网站的VM可以重新映像,日志将丢失。
A better solution is to use Azure diagnostics combined with log4net (would work the same for other logging mechanisms such as NLog). 更好的解决方案是使用Azure诊断结合log4net(对于其他日志记录机制(如NLog)也可以使用)。 Process is sumarrized here: 流程在这里是sumarrized:
Set up local storage as a place on the role instance (virtual machine) where log files are written. 将本地存储设置为写入日志文件的角色实例(虚拟机)上的位置。
Add a element to the diagnostics.wadcfg file to instruct Azure diagnostics to create and use a container in blob storage. 将一个元素添加到diagnostics.wadcfg文件,以指示Azure诊断程序在blob存储中创建和使用容器。
Add a element within to instruct Azure diagnostics to monitor the logging folder within the LogStorage local resource location. 在其中添加元素以指示Azure诊断程序监视LogStorage本地资源位置中的日志记录文件夹。
This way the locally stored logs will be copied to the blob storage. 这样,本地存储的日志将被复制到blob存储。
Full story here: http://justazure.com/microsoft-azure-diagnostics-part-1-introduction/ 全文: http : //justazure.com/microsoft-azure-diagnostics-part-1-introduction/
The best way to log data for Azure VMs or Cloud Services is to use Log4Net to log to disk as well as log information from all your instances to an Azure storage account. 记录Azure VM或云服务数据的最佳方法是使用Log4Net登录磁盘以及将所有实例的日志信息记录到Azure存储帐户。 The advantage is that you will get a more robust solution. 优点是您将获得更强大的解决方案。 If for some reason Azure Diagnostics breaks during a live site, you can still remote into any of the instances and try to diagnose the issue. 如果由于某种原因,Azure诊断程序在实时站点中中断,您仍然可以远程访问任何实例并尝试诊断问题。 For other services such as web apps, where you can't remote into the instances, it is sufficient to log information to Azure Storage accounts. 对于其他服务(例如Web应用程序,您无法远程访问实例),将信息记录到Azure存储帐户就足够了。
It will take you half a day or a day to setup and test but I hope that answers your question. 设置和测试需要半天或一天,但我希望能回答你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.