asp.net - Enterprise Library 3.1 Logging Formatter Template - Include URL Request -
we have custom web app built using ektron v8.0 uses el 3.1 , format template in logging config configured 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 template item request url? without request url querystring parameters, it's difficult debug errors.
there no template item request url. can add request url extended properties information 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 formatter logging dictionary key/values requesturl show in log.
an alternative approach create own iextrainformationprovider populate specific web information interested in.  it's same thing except using 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);      
Comments
Post a Comment