log4net and HttpContext.Current.Url

Vote:
 
Can I configure the log4net appender to add context information such as the current requesting url? I get a lot of errors like: 2007-12-19 10:55:43,532 ERROR [866] - Invalid path encountered: ../../link/031fffbb66d74b95b2e37696a1065916.no/kommuner/0615, Exception: System.Web.HttpException: Cannot use a leading .. to exit above the top directory. at System.Web.Util.UrlPath.ReduceVirtualPath(String path) at System.Web.Util.UrlPath.Reduce(String path) at System.Web.Util.UrlPath.Combine(String appPath, String basepath, String relative) at System.Web.VirtualPath.Combine(VirtualPath relativePath) at System.Web.VirtualPath.Combine(VirtualPath v1, VirtualPath v2) at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath) at EPiServer.Web.FriendlyHtmlRewriteToExternal.IsHtmlUrlValidForRewrite(UrlBuilder contextUrl, UrlBuilder url) But I dont know on what Page this occurs. Any ideas?
#15938
Dec 19, 2007 10:59
Vote:
 

Hi Thomas,

 

You can log the current request URL with log4net using the technique described here

 

http://stackoverflow.com/questions/187284/log4net-not-logging-threadcontext 

 

Did you have any luck fixing this issue? We have the same problem on a project of ours and it is filling up the error logs and making them useless. 

#27064
Jan 15, 2009 13:51
Vote:
 

You can use this module to extend the log4net logs:

https://www.coderesort.com/p/epicode/wiki/Log4NetContextInformation

/Steve

#27077
Jan 16, 2009 10:27
Vote:
 

Hi there did either of you find a fix for this as we're having the same issue?

Thanks,
Cassandra

#28463
Mar 09, 2009 16:30
Vote:
 

I my case I got this error message because there where links to files on external harddrives. But since my solution is an Intranet, that type of links should be allowed for the editors to put in. My solution to this error log spam was to create my own FriendlyUrlRewriteProvider that Inherit from EPiServer.Web.FriendlyUrlRewriteProvider. I Override on method, GetHtmlRewriter(), and call my own FriendlyHtmlRewriteToExternal class that derive from EPiServer.Web.FriendlyHtmlRewriteToExternal class. In my custom FriendlyHtmlRewriteToExternal I Do som extra testing to prevent the exeption from being thrown.

    public class FriendlyUrlRewriteProvider : EPiServer.Web.FriendlyUrlRewriteProvider 
    {
        public override HtmlRewriteToExternal GetHtmlRewriter()
        {
            return new FriendlyHtmlRewriteToExternal(RebaseKind);
        }
    }

    public class FriendlyHtmlRewriteToExternal : EPiServer.Web.FriendlyHtmlRewriteToExternal
    {
        public FriendlyHtmlRewriteToExternal(UrlBuilder.RebaseKind rebaseKind) : base(rebaseKind)
        {
            
        }

        protected override bool IsHtmlUrlValidForRewrite(UrlBuilder contextUrl, UrlBuilder url)
        {
            if (url.Scheme.Equals("file"))
            {
                /*  Added to prevent logfiles filling up with error messages like:
                 * 
                 *  ERROR [5] EPiServer.Web.FriendlyHtmlRewriteToExternal.IsHtmlUrlValidForRewrite - Invalid path encountered: P:/ClueMaxi7.2/clue.exe, 
                 *  Exception: System.Web.HttpException: P:/ClueMaxi7.2/clue.exe er en ugyldig virtuell bane.
                 *  ved System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options)
                 *  ved System.Web.VirtualPathUtility.Combine(String basePath, String relativePath)
                */
                return false;
            }
            return base.IsHtmlUrlValidForRewrite(contextUrl, url);
        }
    }

    In addition you will need to add reference to this provider web.config

<urlRewrite defaultProvider="MyFriendlyUrlRewriteProvider">
      <providers>
        <add name="MyFriendlyUrlRewriteProvider" type="MyProject.Web.FriendlyUrlRewriteProvider,MyProject.Web" />
    

    (EPiServer CMS SDK specify that events like HtmlRewritingUrl can be used for this purpose, but I was not able to figure out how to call these events.)

#42201
Aug 12, 2010 16:15
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.