Exemplo n.º 1
0
        /// <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();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create KLog Instance.
        /// </summary>
        /// <param name="appConfig"></param>
        internal static Guid CreateDynamicInstance(AppConfiguration appConfig)
        {
            try
            {
                Guid instanceId = Guid.NewGuid();

                using (LogInstance logInstance = new LogInstance(KConstants.s_InstanceStart, instanceId, appConfig))
                {
                    if (appConfig.WriteLog)
                    {
                        LogFileWriter.AddInstanceEvent(logInstance);
                    }

                    if (appConfig.WriteVerbose)
                    {
                        //LogVerboseWriter.Write();
                    }
                }

                return(instanceId);
            }
            catch (Exception ex)
            {
                // TODO: Replace => Log.Error($"[KManager].[CreateInstance] - Exception: {ex.ToString()}");

                return(Guid.Empty);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Signals the end of KLog operations for an instance, closing KLog instance log, renaming the KLOG file for sending operation.
        /// </summary>
        internal static void CloseDynamicInstance(Guid instanceId, AppConfiguration appConfig)
        {
            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();
                }
            }
        }
Exemplo n.º 4
0
        /// <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();
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// The log injection funnel is a layer between the Log Type "switch" class and the Logging action classes.
        /// The entry is evaluated for both a (1) log write action and (2) verbose console feedback action.
        /// </summary>
        /// <param name="blockID">Log block (GUID) ID</param>
        /// <param name="blockName">Log block name</param>
        /// <param name="logType">Log type</param>
        /// <param name="logData">Log data payload</param>
        private void LogInjector(Guid instanceId, string filepath, Guid blockID, string blockName, string logType, string logData)
        {
            using (LogRecord logBase = new LogRecord())
            {
                logBase.BlockID    = blockID;
                logBase.LogType    = logType;
                logBase.BlockName  = blockName;
                logBase.LogData    = logData;
                logBase.InstanceID = instanceId;
                logBase.FilePath   = filepath;

                if (config.WriteLog)
                {
                    LogFileWriter.AddRecordEvent(logBase);
                }

                if (config.WriteVerbose)
                {
                    LogVerboseWriter.WriteToConsole(logBase);
                }
            }
        }