I am firing Component save event in SDL Tridion 2011. I have written code like below,
public EventSystem()
{
EventHelper.WriteEventToHTMLLog("S-Constructor");
Subscribe();
EventHelper.WriteEventToHTMLLog("E-Constructor");
}
public void Subscribe()
{
EventHelper.WriteEventToHTMLLog("S-Subscribe");
EventSystem.Subscribe<Component, SaveEventArgs>(OnComponentSavePre, EventPhases.Initiated);
EventHelper.WriteEventToHTMLLog("E-Subscribe");
}
private void OnComponentSavePre(Component comp, SaveEventArgs args, EventPhases phase)
{
EventHelper.WriteEventToHTMLLog("Component save event is fired.");
}
In above code, EventHelper.WriteEventToHTMLLog writes string logs to physical file on server which is object of below class.
public class EventHelper
{
public static void WriteEventToHTMLLog(String strMessage)
{
try
{
string dirPath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
dirPath = @"F:\Tridion\web\RREvent_SystemLogs\RR_EventSystem\";
string FileContent = string.Empty;
string updatedLogs = string.Empty;
updatedLogs = System.DateTime.Now.ToString("HH : mm : ss ") + " = " + strMessage;
if (!Directory.Exists(dirPath + @"\EventLogsComponent"))
{
Directory.CreateDirectory(dirPath + @"\EventLogsComponent");
}
string FileName = "Log_" + System.DateTime.Now.ToString("dd_MM_yyyy") + ".xml";
FileInfo fileInfo = new FileInfo(dirPath + @"\EventLogsComponent\" + FileName);
if (fileInfo.Exists)
{
FileContent = File.ReadAllText(fileInfo.FullName);
FileContent = FileContent.Replace("</Logs>", "<Log>" + updatedLogs + "</Log>" + "</Logs>");
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(FileContent);
xDoc.Save(fileInfo.FullName);
}
else
{
FileContent = "<Logs><Log>" + updatedLogs + "</Log></Logs>";
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(FileContent);
xDoc.Save(fileInfo.FullName);
}
}
catch (Exception e3)
{
}
}
}
Here, I am facing weird problem, When I have fired event very first time, all the logs are written successfully. But when I have uploaded dll second time ( with some changes ), event code is reflected on User Interface properly but new logs are not generated of the event method. ( only subscribe method & constructor logs are written ). And when I have uploaded dll third time, no event log is written in file of any method.
I am confused. Please suggest what would be the cause behind this problem ?
Thanks.