简体   繁体   English

登录Azure

[英]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检查日志文件(双击文件下载它)服务器资源管理器:

Azure网站通过Server Explorer

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:

  1. Set up local storage as a place on the role instance (virtual machine) where log files are written. 将本地存储设置为写入日志文件的角色实例(虚拟机)上的位置。

  2. 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存储中创建和使用容器。

  3. 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存储帐户就足够了。

  1. Logging To Disk: If you have a cloud service, your web role/worker role will only have permission to write to the application disk which is quite small as shown here and here . 记录到磁盘:如果您有云服务,则您的Web角色/辅助角色将只具有写入应用程序磁盘的权限,该磁盘非常小,如此此处所示。 If you are happy with logging not more than say 200-300 MB of disk space then you are good. 如果您对记录不超过200-300 MB的磁盘空间感到满意,那么您就是好的。 However, if you would like to log more then it might be best to use the concept of LocalStorage which will allow you to reserve space on the C drive which has a huge amount of space (for Small PaaS VMs Drive C has 225 GB roughly while the application drive (E:/F:) has 1.5 GB of space). 但是,如果您想记录更多,那么最好使用LocalStorage的概念,这将允许您在具有大量空间的C驱动器上保留空间(对于Small PaaS VM,驱动器C大致具有225 GB而应用程序驱动器(E:/ F :)有1.5 GB的空间)。 You can learn how to use local storage here . 您可以在此处了解如何使用本地存储。
  2. Logging to Azure Storage Account: You will need to active Azure Diagnostics as shown here . 登录到Azure存储账户:您需要积极Azure诊断如图所示这里 Furthermore, you will have to add a Trace Appender to Log4Net as shown here . 此外,你将有一个跟踪追加程序添加到log4net的如图所示这里

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM