Code Coverage by Clover.NET

Put log in IIS virtual path (map ~/logpath)?

View: New views
2 Messages — Rating Filter:   Alert me  

Put log in IIS virtual path (map ~/logpath)?

by sideout :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How would I go about doing this?

Re: Put log in IIS virtual path (map ~/logpath)?

by sideout :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I ended up making my own LayoutRenderer and it seems to work so far.

using System;
using System.Text;
using System.Web;
 
using NLog;
 
namespace NLogUtils
{
    [LayoutRenderer("virtualpath")]
    public sealed class ScratchDirRenderer: LayoutRenderer
    {
        private string _vPath = String.Empty;
         
        // this is an example of a configurable parameter
        public string VPath
        {
            get { return _vPath; }
            set { _vPath = value; }
        }

        protected override int GetEstimatedBufferSize(LogEventInfo ev)
        {
                // roughly max path size of 255
            return 255;
        }
 
        protected override void Append(StringBuilder builder, LogEventInfo ev)
        {
                builder.Append(ApplyPadding(HttpContext.Current.Server.MapPath(VPath)));
        }
    }
}

<target name="file" xsi:type="File" fileName="${virtualpath:vPath=~/logpath/}${shortdate}.txt"/>