public static void Init()
        {
            try
            {
                ConfigurationBag.LoadConfiguration();
                Enabled = ConfigurationBag.Configuration.LoggingEngineEnabled;
                //Load logging external component
                var loggingComponent = Path.Combine(
                    ConfigurationBag.Configuration.DirectoryOperativeRootExeName,
                    ConfigurationBag.Configuration.LoggingComponent);

                Debug.WriteLine("Check Abstract Logging Engine.");

                //Create the reflection method cached
                var assembly = Assembly.LoadFrom(loggingComponent);
                //Main class logging
                var assemblyClass = (from t in assembly.GetTypes()
                                     let attributes = t.GetCustomAttributes(typeof(LogContract), true)
                                                      where t.IsClass && attributes != null && attributes.Length > 0
                                                      select t).First();


                LogEngineComponent = Activator.CreateInstance(assemblyClass) as ILogEngine;

                Debug.WriteLine("LogEventUpStream - Inizialize the external log");

                LogEngineComponent.InitLog();

                Debug.WriteLine("Initialize Abstract Logging Engine.");

                Debug.WriteLine("LogEventUpStream - CreateEventSource if not exist");
                if (!EventLog.SourceExists(EventViewerSource))
                {
                    EventLog.CreateEventSource(EventViewerSource, EventViewerLog);
                }

                //Create the QueueConsoleMessage internal queue
                Debug.WriteLine(
                    "LogEventUpStream - logQueueConsoleMessage.OnPublish += LogQueueConsoleMessageOnPublish");
                QueueConsoleMessage =
                    new LogQueueConsoleMessage(
                        ConfigurationBag.Configuration.ThrottlingConsoleLogIncomingRateNumber,
                        ConfigurationBag.Configuration.ThrottlingConsoleLogIncomingRateSeconds);
                QueueConsoleMessage.OnPublish += QueueConsoleMessageOnPublish;

                //Create the QueueAbstractMessage internal queue
                Debug.WriteLine(
                    "LogEventUpStream - logQueueAbstractMessage.OnPublish += LogQueueAbstractMessageOnPublish");
                QueueAbstractMessage = new LogQueueAbstractMessage(
                    ConfigurationBag.Configuration.ThrottlingLsiLogIncomingRateNumber,
                    ConfigurationBag.Configuration.ThrottlingLsiLogIncomingRateSeconds);
                QueueAbstractMessage.OnPublish += QueueAbstractMessageOnPublish;
                Debug.WriteLine("LogEventUpStream - Log Queues initialized.");
            }
            catch (Exception ex)
            {
                DirectEventViewerLog($"Error in {MethodBase.GetCurrentMethod().Name} - {ex.Message}", 1);
                WriteLog(
                    ConfigurationBag.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.LogLevelError,
                    Constant.TaskCategoriesError,
                    ex,
                    Constant.LogLevelError);
                Environment.Exit(0);
            }
        }
Beispiel #2
0
        public static void Init()
        {
            try
            {
                Configuration.LoadConfiguration();
                Enabled = Configuration.LoggingEngineEnabled();
                Verbose = Configuration.LoggingVerbose();
                //Load logging external component
                var loggingComponent = Path.Combine(
                    Configuration.DirectoryOperativeRootExeName(),
                    Configuration.LoggingComponent());

                DirectConsoleWriteLine("Check Abstract Logging Engine.", ConsoleColor.Yellow);

                //Create the reflection method cached
                var assembly = Assembly.LoadFrom(loggingComponent);
                //Main class logging
                var assemblyClass = (from t in assembly.GetTypes()
                                     let attributes = t.GetCustomAttributes(typeof(LogContract), true)
                                                      where t.IsClass && attributes != null && attributes.Length > 0
                                                      select t).First();

                var classAttributes = assemblyClass.GetCustomAttributes(typeof(LogContract), true);

                if (classAttributes.Length > 0)
                {
                    Debug.WriteLine("LogEventUpStream - InitLog caller");
                    methodLogInfoInit = assemblyClass.GetMethod("InitLog");
                    Debug.WriteLine("LogEventUpStream - WriteLog caller");
                    methodLogInfoWrite = assemblyClass.GetMethod("WriteLog");
                }

                classInstance = Activator.CreateInstance(assemblyClass, null);

                Debug.WriteLine("LogEventUpStream - Inizialize the external log");
                methodLogInfoInit.Invoke(classInstance, null);
                DirectConsoleWriteLine("Initialize Abstract Logging Engine.", ConsoleColor.Yellow);

                Debug.WriteLine("LogEventUpStream - CreateEventSource if not exist");
                if (!EventLog.SourceExists(EventViewerSource))
                {
                    EventLog.CreateEventSource(EventViewerSource, EventViewerLog);
                }

                //Create the QueueConsoleMessage internal queue
                Debug.WriteLine(
                    "LogEventUpStream - logQueueConsoleMessage.OnPublish += LogQueueConsoleMessageOnPublish");
                QueueConsoleMessage =
                    new LogQueueConsoleMessage(
                        Configuration.ThrottlingConsoleLogIncomingRateNumber(),
                        Configuration.ThrottlingConsoleLogIncomingRateSeconds());
                QueueConsoleMessage.OnPublish += QueueConsoleMessageOnPublish;

                //Create the QueueAbstractMessage internal queue
                Debug.WriteLine(
                    "LogEventUpStream - logQueueAbstractMessage.OnPublish += LogQueueAbstractMessageOnPublish");
                QueueAbstractMessage = new LogQueueAbstractMessage(
                    Configuration.ThrottlingLsiLogIncomingRateNumber(),
                    Configuration.ThrottlingLsiLogIncomingRateSeconds());
                QueueAbstractMessage.OnPublish += QueueAbstractMessageOnPublish;
                Debug.WriteLine("LogEventUpStream - Log Queues initialized.");
            }
            catch (Exception ex)
            {
                LogEngine.EventViewerWriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesError,
                    ex,
                    EventLogEntryType.Error);
                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesError,
                    ex,
                    EventLogEntryType.Error);
                Thread.Sleep(Configuration.WaitTimeBeforeRestarting());
                Environment.Exit(0);
            }
        }