コード例 #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();
                }
            }
        }
コード例 #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);
            }
        }
コード例 #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();
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Instance console formatting.
        /// </summary>
        /// <param name="logInstance"></param>
        public static void WriteToConsole(LogInstance logInstance)
        {
            lock (_lock)
            {
                Console.Write(" INSTANCE: ");

                Console.Write(logInstance.InstanceID);

                Console.Write(" | DATA: ");

                ColorTypeMatch(logInstance.InstanceStatus);
                Console.Write("{0} \n\r", logInstance.InstanceStatus);
                Console.ResetColor();
            }
        }
コード例 #5
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();
                }
            }
        }