简体   繁体   English

如何在Windows Azure的Web.config中更改所有Web角色的日志记录设置?

[英]How to change the Logging settings in Web.config on Windows Azure for all Web Roles?

ASP.NET application on Windows Azure. Windows Azure上的ASP.NET应用程序。 The application is scalable and runs on 1..N Web role instances. 该应用程序是可伸缩的,并且可以在1..N Web角色实例上运行。

We have log4net write to the Windows Event log and have Windows Azure Diagnostics consolidate to Azure storage. 我们已将log4net写入Windows事件日志,并已将Windows Azure诊断合并到Azure存储。

At the moment the log4net configuration is stored in Web.config. 目前,log4net配置存储在Web.config中。

For application logging we have the following requirements: 对于应用程序日志记录,我们具有以下要求:

  1. Ability to specify a list of one or more types of log entries to write to the log 能够指定要写入日志的一种或多种类型的日志条目的列表

  2. Ability to specify the level at which log entries are written to the log (per log entry) 能够指定将日志条目写入日志的级别(每个日志条目)

The first requirement is met by the loggers naming convention. 记录器命名约定满足第一个要求。 Loggers define a hierarchy and give the programmer run-time control on which statements are printed or not. 记录器定义了一个层次结构,并赋予程序员运行时控制是否打印语句的能力。

ILog log = LogManager.GetLogger("Davanti.WMS.Core.Logic.Inventory");

The second requirement can be achieved by using the logging levels DEBUG, INFO, WARN, ERROR and FATAL. 通过使用日志记录级别DEBUG,INFO,WARN,ERROR和FATAL可以达到第二个要求。

log.Debug("Process has completed");

Current situation 现在的情况

We have only one log4net configuration in the Web.config file that redirects to the Windows Event log. Web.config文件中只有一个log4net配置可重定向到Windows事件日志。 And control what to log (see requirement 1) and the depth (level) to log (see requirement 2) in application code base on settings stored in the central database. 和控制记录的内容 (见要求1)和深度 (高度)进行登录(见第2要求)存储在中央数据库设置在应用程序的代码库。

This approach will have a negative effect on application performance because the application itself will have to check if certain messages needs to be logged or not (synchronously) instead on the logging framework (asynchronously). 这种方法将对应用程序性能产生负面影响,因为应用程序本身将必须检查(同步)是否需要记录某些消息,而不是(异步)检查某些消息。

Required situation 必要情况

We want to control what to log and logging level from the log4net settings. 我们想通过log4net设置控制要记录的内容和记录级别。 The problem is that we have to apply the log4net settings on all Windows Azure Web role instances. 问题是我们必须在所有 Windows Azure Web角色实例上应用log4net设置。 What is the best approach for this? 最好的方法是什么?

Also we would like to have a more user friendly way to enable logging (for example by a consultant). 另外,我们希望有一种更加用户友好的方式来启用日志记录(例如由顾问来进行)。 What are the possibilities? 有什么可能?

Like for example using the Enterprise Library Configuration editor. 例如使用企业库配置编辑器。 A visual representation of the confoguration settings. 配置设置的直观表示。 http://img651.imageshack.us/img651/930/logging.jpg http://img651.imageshack.us/img651/930/logging.jpg

The default configuration provider will look at the app.config or web.config in your case. 默认配置提供程序将根据您的情况查看app.config或web.config。 However you can use the XmlConfigurator class to load configurations from a Stream 但是,您可以使用XmlConfigurator类从Stream加载配置。

http://logging.apache.org/log4net/release/sdk/log4net.Config.XmlConfigurator.Configure_overload_7.html http://logging.apache.org/log4net/release/sdk/log4net.Config.XmlConfigurator.Configure_overload_7.html

In your role configuration you can specify a blob location then use a blob client object from the Azure storage SDK and load the xml from a single blob location. 在角色配置中,您可以指定一个Blob位置,然后使用Azure存储SDK中的Blob客户端对象,并从单个Blob位置加载xml。

Log4Net configuration: http://logging.apache.org/log4net/release/manual/configuration.html Log4Net配置: http : //logging.apache.org/log4net/release/manual/configuration.html

This is similar to the Azure diagnostics configuration which uses an xml blob. 这类似于使用xml blob的Azure诊断配置。

The caveat to this is that you need to do some more implementation like regular queuing for updates to the file if you want to do live changes to your logging. 需要注意的是,如果要对日志记录进行实时更改,则需要执行更多的实现,例如对文件更新进行常规排队。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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