Change Logging Directory
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;
);
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
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;
Where is Telerik.Microsoft.Practices.EnterpriseLibrary.Logging located? I mean which DLL has this class?
@Abdulmunem
using
Telerik.Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using
Telerik.Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
/// <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);
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?