+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Change Logging Directory

Change Logging Directory

6 posts, 1 answered
  1. James
    James avatar
    19 posts
    Registered:
    21 Jan 2011
    18 May 2011
    Link to this post
    We have a TeamCity integration deploying builds for us to various environments and we have one last snag to solve - if the site is 'warm' the error log is locked preventing MSDeploy from pushing the site.  I found an old post with directions on how to move logging directory but it's not working for us.

    Based on that post I created this function and call it in Application_Start in global.asax.cs
    protected void SetupSitefinityLogPath()
    {
               // pull in the app config setting
               var errorLogPath = ConfigurationManager.AppSettings["SitefinityLogPath"];
               ObjectFactory.Initializing += new EventHandler<Telerik.Sitefinity.Data.ExecutingEventArgs>(
                   delegate(object s, Telerik.Sitefinity.Data.ExecutingEventArgs args)
                   {
                       if (args.CommandName == "ConfigureLogging")
                       {
                           args.Cancel = true;
                           var errorFileName = errorLogPath;
                       }
                   });
           }

    I force SF to error out by visiting a bogus URL but it looks like the Logger wasn't initialized completely, since I flagged .Cancel to true.  Here is the error I receive :

    The type LogWriter cannot be constructed. You must configure the container to supply this value.

    Are there additional function calls I need to make in my delegate to finish initializing the logger?
  2. Nikolay Datchev
    Nikolay Datchev avatar
    87 posts
    Registered:
    01 Nov 2016
    27 May 2011
    Link to this post
    Hello James,

    We use Enterprise library Logging Application Block. The error log is implemented using RollingFlatFileTraceListener. You can hook like this here(see code below) and change some settings of the trace listener. By the way, there are 2 more listeners configured - Trace and UpgradeTrace. UpgradeTrace tracks the success/fail of DB upgrade procedure when you upgrade to a new version of Sitefinity and also writes to /App_Data/Sitefinity/Logs/ by default. The way you did it totally cancels the configuration of the error log listener and the other 2 listeners, which causes the problems you encounter.

    public class Global : System.Web.HttpApplication
        {

            protected void Application_Start(object sender, EventArgs e)
            {
                ObjectFactory.Initialized += ConfigInitialize;
            }

            private void ConfigInitialize(object s, ExecutedEventArgs args)
            {
                if (args.CommandName == "ConfigureLogging")
                {
                    var builder = args.Data as ConfigurationSourceBuilder;
                    var errorLog = ((Telerik.Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings)builder.Get("loggingConfiguration")).TraceListeners.SingleOrDefault(l => l.Name == "ErrorLog")
                        as Telerik.Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData;
                   //this is the default path
                    var fileName = errorLog.FileName;
                   //you can change this to another path

               

                }

            }

    Regards,
    Nikolay Datchev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. James
    James avatar
    19 posts
    Registered:
    21 Jan 2011
    02 Jun 2011
    Link to this post
    Thanks so much for this!  I had to make a small change to get it to work,I had to adjust the Rolling Flat file to just Flat File like seen in the complete code snippet below.

    protected void SetupSitefinityLogPath(object s, ExecutedEventArgs args)
     {
        if (args.CommandName == "ConfigureLogging")
        {
            var builder = args.Data as ConfigurationSourceBuilder;
            var errorLog = ((Telerik.Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings)builder.Get("loggingConfiguration")).TraceListeners.SingleOrDefault(l => l.Name == "ErrorLog")
                as Telerik.Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData;
                     
            var baseLogPath = ConfigurationManager.AppSettings["SitefinityLogPath"];
            var timestamp = DateTime.Now.ToString("yyyy.MM.dd.HHmm");
            var lFileName = string.Format("{0}.{1}.txt", baseLogPath, timestamp);
            errorLog.FileName = lFileName;
        }
    }

    It's creating log files in our new path now as desired, thanks again!
  4. Wirestorm
    Wirestorm avatar
    1 posts
    Registered:
    24 Mar 2011
    06 Jun 2012
    Link to this post
    Where is Telerik.Microsoft.Practices.EnterpriseLibrary.Logging located? I mean which DLL has this class?
  5. James
    James avatar
    19 posts
    Registered:
    21 Jan 2011
    06 Jun 2012
    Link to this post
    @Abdulmunem

    I took a look at our code for you, it appears that we are utilizing these two namespaces:
    using Telerik.Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
    using Telerik.Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;

    and just in case anything has changed over the past several months, here is our current "move log file directory" function:

                /// <summary>
           /// Move the sitefinity log path to a better location specified in web.config
           /// </summary>
           protected void SetupSitefinityLogPath(object s, ExecutedEventArgs args)
           {
               if (args.CommandName == "ConfigureLogging")
               {
                   var builder = args.Data as ConfigurationSourceBuilder;
     
                   if (builder != null)
                   {
                       var baseLogPath = ConfigurationManager.AppSettings["SitefinityLogPath"];
                       var timestamp = DateTime.Now.ToString("yyyy.MM.dd.HHmm");
     
                       var sfTraceListeners =((LoggingSettings)builder.Get("loggingConfiguration")).TraceListeners.Cast<RollingFlatFileTraceListenerData>();
     
                       foreach (var sfTraceListener in sfTraceListeners)
                       {
                           sfTraceListener.FileName = string.Format(sfTraceListener.Name.ToLower().EndsWith("log") ? "{0}{1}.{2}.txt" : "{0}{1}Log.{2}.txt",
                                                                    baseLogPath, sfTraceListener.Name, timestamp);
                       }
                   }
               }
           }

    Hope this helps!
  6. Brandon
    Brandon avatar
    1 posts
    Registered:
    15 Dec 2006
    23 Jul 2013
    Link to this post
    If this is based on TraceListeners than shouldn't we be able to modify the output location through the <system.diagnostics/> section of the web.config?
6 posts, 1 answered