/// <summary> /// Start a new Kiroku logging instance, log file. /// </summary> public static void Open() { string appName = Assembly.GetCallingAssembly().GetName().Name.ToUpper(); Guid instanceId = Guid.NewGuid(); AppConfiguration appConfig = KConfiguration.GetConfig(appName); if (appConfig.Dynamic) { throw new Exception($"Dynamic logging is set to true. This is a static only method."); } KConfiguration.AddStaticInstaneId(instanceId, appName); using (LogInstance logInstance = new LogInstance(KConstants.s_InstanceStart, instanceId, appConfig)) { if (appConfig.WriteLog) { LogFileWriter.AddInstanceEvent(logInstance); } if (appConfig.WriteVerbose) { //LogVerboseWriter.Write(); } } }
/// <summary> /// Log constructor, boot strapping dynamic klog block id and block name -- nested inside primary node's instance id. /// </summary> /// <param name="blockName"></param> /// <param name="klog"></param> public KLog(string blockName, KLog klog) { blockID = Guid.NewGuid(); this.blockName = blockName; string appName = Assembly.GetCallingAssembly().GetName().Name.ToUpper(); config = KConfiguration.GetConfig(appName); if (!config.Dynamic) { throw new Exception($"Linked KLog's only supported in Dynamic logging mode."); } else { instanceId = klog.instanceId; } Start(); }
/// <summary> /// Boot strapping block id and block name -- create instance if dynamically logging. /// </summary> /// <param name="blockName">The friendly block name</param> public KLog(string blockName) { blockID = Guid.NewGuid(); this.blockName = blockName; string appName = Assembly.GetCallingAssembly().GetName().Name.ToUpper(); config = KConfiguration.GetConfig(appName); if (config.Dynamic) { instanceId = KManager.CreateDynamicInstance(config); entryNode = true; } else { instanceId = KConfiguration.GetStaticInstanceId(appName); } Start(); }
/// <summary> /// Close the current Kiroku logging instance, marking the file for agent transmission. /// </summary> public static void Close() { string appName = Assembly.GetCallingAssembly().GetName().Name.ToUpper(); AppConfiguration appConfig = KConfiguration.GetConfig(appName); if (appConfig.Dynamic) { throw new Exception($"Dynamic logging is set to true. This is a static only method."); } Guid instanceId = KConfiguration.GetStaticInstanceId(appName); using (LogInstance logInstance = new LogInstance(KConstants.s_InstanceStop, instanceId, appConfig)) { if (appConfig.WriteLog) { LogFileWriter.AddInstanceEvent(logInstance); try { string newFilePath = appConfig.FullFilePath.Replace(KConstants.s_WritingToLog, KConstants.s_ReadyToSend); // Rename from KLOG_W_$(guid) to KLOG_S_$(guid) -- this will maket the log available for transmission File.Move(appConfig.FullFilePath + instanceId.ToString() + KConstants.s_FileExt, (newFilePath + instanceId.ToString() + KConstants.s_FileExt)); } catch (Exception ex) { // TODO: Replace => Log.Error($"[KManager].[EndInstance] - Exception: {ex.ToString()}"); } } if (appConfig.WriteVerbose) { //LogVerboseWriter.Write(); } } }