Ejemplo n.º 1
0
        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);
            }
        }