企业库3.1格式化记录模板 - 包括URL请求 [英] Enterprise Library 3.1 Logging Formatter Template - Include URL Request

查看:123
本文介绍了企业库3.1格式化记录模板 - 包括URL请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在使用它采用EL 3.1晔V8.0,并在日志配置的格式模板建立了一个自定义的Web应用程序配置为这样的:

We have a custom web app built using Ektron v8.0 which uses EL 3.1 and the format template in the logging config is configured as such:

<add
      name="Text Formatter"
      type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
      template="Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
Title:{title}
Extended Properties: {dictionary({key} - {value}
)}"
                />

是否有请求URL模板项目?如果没有与查询字符串参数请求的URL,这是难以调试的错误。

Is there a template item for Request URL? Without the request url with querystring parameters, it's difficult to debug errors.

推荐答案

有对于请求的URL专门无模板项目。你可以请求URL添加到扩展属性自己,这样信息将被记录:

There is no template item specifically for the request URL. You can add the request URL to the extended properties yourself so that the information is logged:

string requestUrl = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;

Dictionary<string, object> dictionary = new Dictionary<string, object>();
dictionary.Add("RequestUrl", requestUrl);

Logger.Write("My message", dictionary);

由于格式是记录所有字典键/值的RequestUrl将在日志中显示出来。

Since the formatter is logging all dictionary key/values your RequestUrl will show up in the log.

这是另一种办法是创建自己的 IExtraInformationProvider 来填充你感兴趣的特定Web信息。这真是除了使用企业库接口同样的事情。

An alternative approach would be to create your own IExtraInformationProvider to populate the specific web information you are interested in. It's really the same thing except using an Enterprise Library interface.

public class WebContextInformationProvider : IExtraInformationProvider
{
    public void PopulateDictionary(IDictionary<string, object> dict)
    {
        dict["RequestUrl"] = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;
    }
}

Dictionary<string, object> dictionary = new Dictionary<string, object>();
WebContextInformationProvider webContext = new WebContextInformationProvider();

webContext.PopulateDictionary(dictionary);

Logger.Write("My message", dictionary);

这篇关于企业库3.1格式化记录模板 - 包括URL请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆