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

Forums / Bugs & Issues / Sitefinity 5.3 Change Sitefinity Log location

Sitefinity 5.3 Change Sitefinity Log location

2 posts, 0 answered
  1. Phani
    Phani avatar
    9 posts
    Registered:
    18 Mar 2014
    20 Apr
    Link to this post

    I am using a code from the following link in global.asax to setup my own sitefinity log path.

    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 did not work for me though. When I debug, I see that the following does not return anything.

    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;

     

    Since errorLog is null, the last line errorLog.FileName returns a null reference exception. Can someone help me on how to resolve the issue.  How do I verify l.Name = "ErrorLog" is the right query there, is there a setting somewhere in sitefinity backend where I can lookup the exact name?

     

  2. Pavel Benov
    Pavel Benov avatar
    21 posts
    Registered:
    26 Aug 2016
    28 Apr
    Link to this post
    Hi Phani,

    Try casting to RollingFlatFileTraceListenerData instead of FlatFileTraceListenerData as per the last provided solution in the forum thread:

    http://www.sitefinity.com/developer-network/forums/general-discussions-/change-logging-directory

    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);
                       }
                   }
               }

    Regards,
    Pavel Benov
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered