我们有一个使用 Ektron v8.0 构建的自定义 Web 应用程序,该应用程序使用 EL 3.1,并且日志记录配置中的格式模板配置如下:
<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,则很难调试错误。
没有专门针对请求 URL 的模板项。您可以自己将请求 URL 添加到扩展属性,以便记录信息:
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 将显示在日志中。
另一种方法是创建您自己的IExtraInformationProvider
填充您感兴趣的特定 Web 信息。除了使用企业库界面之外,这实际上是同一件事。
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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)