2

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

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

Dave Harding
  • 1,280
  • 2
  • 16
  • 31

1 Answers1

1

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);

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

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);
Randy Levy
  • 22,566
  • 4
  • 68
  • 94
  • I've looked at the msdn article on the 3.1 logging and I don't see where the documentation is for the templates. Any ideas? I'll accept your answer because I think that's the only viable solution. Thanks for a nice, clear, concise answer. – Dave Harding Feb 10 '11 at 16:04
  • @Dave: I couldn't find formal documentation on the template. This is the best I could find from [The Definitive Guide to Enterprise Library](http://books.google.ca/books?id=eZXOfFiv6A4C&lpg=PA298&ots=Wx-h_siJnE&pg=PA298#v=onepage&q&f=false). – Randy Levy Apr 14 '11 at 19:54