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