Enterprise Library 3.1. Register Formatter Template - Enable URL request.

We have a custom web application built using Ektron v8.0 that uses EL 3.1, and the format template in the logging configuration is configured as follows:

<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} )}" /> 

Is there a template element for the request url? Without a url request with querystring parameters, it is difficult to debug errors.

+2
source share
1 answer

There is no template element for the request URL. You can add the request URL to the advanced 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); 

Since the formatter logs all dictionary words / meanings, your RequestUrl will be displayed in the log.

An alternative approach would be to create your own IExtraInformationProvider to populate the specific web information you are interested in. This is really the same except using the 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); 
+1
source

All Articles