public bool LogEvent(TheEventLogData pItem) { if (pItem == null) { return(false); } bool bRet = false; List <TheThing> tDevList = TheThingRegistry.GetThingsOfEngine(MyBaseThing.EngineName); if (tDevList?.Count > 0) { foreach (TheThing tDev in tDevList) { var tTwin = tDev.GetObject() as ICDELoggerEngine; var tRes = tTwin?.LogEvent(pItem); if (!bRet && tRes == true) { bRet = true; } } } if (PublishEvents) //This allows to have a logger on a different node { TheCommCore.PublishCentral(new TSM(eEngineName.ContentService, eEngineEvents.NewEventLogEntry, pItem.EventLevel, TheCommonUtils.SerializeObjectToJSONString(pItem)), true); } return(bRet); }
public override bool LogEvent(TheEventLogData pItem) { if (!IsConnected) { return(false); } return(WriteLogToFile(pItem, true)); }
internal TheStorageMirror <TheEventLogData> MyRuleEventLog; //The Storage Container for data to store public override bool LogEvent(TheEventLogData pData) { if (!MyRuleEventLog.IsReady) { return(false); } MyRuleEventLog.AddAnItem(pData); return(true); }
public bool LogEvent(string ActionText) { TheEventLogData tSec = new TheEventLogData { EventTime = DateTimeOffset.Now, EventLevel = eMsgLevel.l4_Message, StationName = TheBaseAssets.MyServiceHostInfo.GetPrimaryStationURL(false), EventName = TheCommonUtils.GenerateFinalStr(MyBaseThing.FriendlyName, MyBaseThing) }; if (!string.IsNullOrEmpty(tSec.EventName)) { tSec.EventName = tSec.EventName.Replace("%OldValue%", TriggerOldValue); } tSec.EventTrigger = TheThingRegistry.GetThingByMID(TheCommonUtils.CGuid(TriggerObject))?.FriendlyName; tSec.ActionObject = ActionText; var tEng = MyBaseEngine.GetBaseThing().GetObject() as TheRulesEngine; tEng?.LogEvent(tSec); return(true); }
public virtual bool LogEvent(TheEventLogData pItem) { return(false); }
public override bool LogEvent(TheEventLogData pItem) { return(base.LogEvent(pItem)); }
public bool LogEvent(TheEventLogData pData) { TheLoggerFactory.LogEvent(pData); return(false); }
private bool WriteLogToFile(TheEventLogData pLogItem, bool WaitForLock) { if (pLogItem == null || string.IsNullOrEmpty(pLogItem.EventCategory)) { return(false); } if (mWriteToConsole) { Console.WriteLine($"{pLogItem.EventCategory} : {TheCommonUtils.GetDateTimeString(pLogItem.EventTime, -1)} : {pLogItem.EventName} : {pLogItem.EventString}"); } if (string.IsNullOrEmpty(mLogFilePath) && string.IsNullOrEmpty(TheThing.GetSafePropertyString(MyBaseThing, "LogFilePath"))) { return(false); } if (EachCategoryInOwnFile) { //TODO: Tune with array of EventCategory Log file names //MyCurLog = mLogFilePath + string.Format("\\{1}_{0:yyyMMdd_HHmmss}.txt", DateTime.Now,pLogItem.EventCategory); //MyCurLog = TheCommonUtils.cdeFixupFileName(MyCurLog); //TheCommonUtils.CreateDirectories(MyCurLog); } if (EachDayInOwnFile && mLogFileDate.Day != DateTimeOffset.Now.Day) { LogFilePath = MyCurLog = TheCommonUtils.cdeFixupFileName(mLogFilePath + string.Format("\\LOG_{0:yyyMMdd_HHmmss}.txt", DateTime.Now)); LogFileDate = mLogFileDate = DateTimeOffset.Now; } // ReSharper disable once EmptyEmbeddedStatement if (WaitForLock) { while (TheCommonUtils.cdeIsLocked(writeLock)) { TheCommonUtils.SleepOneEye(50, 50); } } if (!TheCommonUtils.cdeIsLocked(writeLock)) { lock (writeLock) { var bLogFileExists = System.IO.File.Exists(MyCurLog); if (mMaxLogFileSize > 0 && bLogFileExists) { try { System.IO.FileInfo f2 = new System.IO.FileInfo(MyCurLog); if (f2.Length > mMaxLogFileSize * (1024 * 1024)) { MyCurLog = LogFilePath = TheCommonUtils.cdeFixupFileName(mLogFilePath + string.Format("\\LOG_{0:yyyMMdd_HHmmss}.txt", DateTime.Now)); LogFileDate = mLogFileDate = DateTimeOffset.Now; } } catch { //ignored } bLogFileExists = System.IO.File.Exists(MyCurLog); } try { using (System.IO.StreamWriter fs = new System.IO.StreamWriter(MyCurLog, bLogFileExists)) { if (EachCategoryInOwnFile) { fs.WriteLine($"{pLogItem.EventTime} : {TheCommonUtils.GetDateTimeString(pLogItem.EventTime, -1)} : {pLogItem.EventString}"); } else { fs.WriteLine($"{pLogItem.EventCategory} : {TheCommonUtils.GetDateTimeString(pLogItem.EventTime,-1)} : {pLogItem.EventName} : {pLogItem.EventString}"); } } } catch { //ignored } } } return(true); }
void sinkNewEvent(ICDEThing sender, object pLogEntry) { TheEventLogData pData = pLogEntry as TheEventLogData; WriteLogToFile(pData, true); }