Change Logging Directory

Posted by Community Admin on 03-Aug-2018 18:17

Change Logging Directory

All Replies

Posted by Community Admin on 18-May-2011 00:00

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?

Posted by Community Admin on 27-May-2011 00:00

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

Posted by Community Admin on 02-Jun-2011 00:00

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!

Posted by Community Admin on 06-Jun-2012 00:00

Where is Telerik.Microsoft.Practices.EnterpriseLibrary.Logging located? I mean which DLL has this class?

Posted by Community Admin on 06-Jun-2012 00:00

@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") ? "01.2.txt" : "01Log.2.txt",
                                                                baseLogPath, sfTraceListener.Name, timestamp);
                   
               
           
       

Hope this helps!

Posted by Community Admin on 23-Jul-2013 00:00

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?

This thread is closed