public void CreateEventLogExportMasterObject()
 {
     using (EventLogExportMaster exporter = new EventLogExportMaster())
     {
         exporter.SetEventLogPath(string.Empty);
         exporter.SetTarget(null);
         exporter.NewDataAvailable();
         exporter.SendData();
     }
 }
        public static void ExportToTargetStorage(EventLogExportSettings eventLogSettings, IEventLogOnTarget targetStorage)
        {
            if (!Directory.Exists(eventLogSettings.EventLogPath))
            {
                throw new Exception("Каталог данных журнала регистрации не обнаружен.");
            }

            using (EventLogExportMaster exporter = new EventLogExportMaster())
            {
                exporter.SetEventLogPath(eventLogSettings.EventLogPath);
                exporter.SetTarget(targetStorage);

                exporter.BeforeExportData  += BeforeExportData;
                exporter.AfterExportData   += AfterExportData;
                exporter.OnErrorExportData += OnErrorExportData;

                while (exporter.NewDataAvailable())
                {
                    exporter.SendData();
                }
            }
        }
Beispiel #3
0
        static void Main()
        {
            IConfiguration Configuration = new ConfigurationBuilder()
                                           .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                           .Build();

            IConfigurationSection eventLogSection = Configuration.GetSection("EventLog");
            string eventLogPath         = eventLogSection.GetValue("SourcePath", string.Empty);
            int    watchPeriodSeconds   = eventLogSection.GetValue("WatchPeriod", 60);
            int    watchPeriodSecondsMs = watchPeriodSeconds * 1000;
            bool   useWatchMode         = eventLogSection.GetValue("UseWatchMode", false);
            int    portion = eventLogSection.GetValue("Portion", 1000);

            IConfigurationSection informationSystemSection = Configuration.GetSection("InformationSystem");
            string informationSystemName        = informationSystemSection.GetValue("Name", string.Empty);
            string informationSystemDescription = informationSystemSection.GetValue("Description", string.Empty);

            if (string.IsNullOrEmpty(eventLogPath))
            {
                Console.WriteLine("Не указан каталог с файлами данных журнала регистрации.");
                Console.WriteLine("Для выхода нажмите любую клавишу...");
                Console.Read();
                return;
            }

            Console.WriteLine();
            Console.WriteLine();

            string connectionString = Configuration.GetConnectionString("EventLogDatabase");
            var    optionsBuilder   = new DbContextOptionsBuilder <EventLogContext>();

            optionsBuilder.UseSqlServer(connectionString);

            using (EventLogExportMaster exporter = new EventLogExportMaster())
            {
                exporter.SetEventLogPath(eventLogPath);

                EventLogOnSQLServer target = new EventLogOnSQLServer(optionsBuilder.Options, portion);
                target.SetInformationSystem(new InformationSystemsBase()
                {
                    Name        = informationSystemName,
                    Description = informationSystemDescription
                });
                exporter.SetTarget(target);

                exporter.BeforeExportData  += BeforeExportData;
                exporter.AfterExportData   += AfterExportData;
                exporter.OnErrorExportData += OnErrorExportData;

                _beginPortionExport = DateTime.Now;
                if (useWatchMode)
                {
                    while (true)
                    {
                        if (Console.KeyAvailable)
                        {
                            if (Console.ReadKey().KeyChar == 'q')
                            {
                                break;
                            }
                        }

                        while (exporter.NewDataAvailable())
                        {
                            exporter.SendData();
                            Thread.Sleep(watchPeriodSecondsMs);
                        }
                    }
                }
                else
                {
                    while (exporter.NewDataAvailable())
                    {
                        exporter.SendData();
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Для выхода нажмите любую клавишу...");
            Console.Read();
        }
        static void Main()
        {
            IConfiguration Configuration = new ConfigurationBuilder()
                                           .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                           .Build();

            IConfigurationSection eventLogSection = Configuration.GetSection("EventLog");
            string eventLogPath         = eventLogSection.GetValue("SourcePath", string.Empty);
            int    watchPeriodSeconds   = eventLogSection.GetValue("WatchPeriod", 60);
            int    watchPeriodSecondsMs = watchPeriodSeconds * 1000;
            bool   useWatchMode         = eventLogSection.GetValue("UseWatchMode", false);
            int    portion = eventLogSection.GetValue("Portion", 1000);

            IConfigurationSection informationSystemSection = Configuration.GetSection("InformationSystem");
            string informationSystemName        = informationSystemSection.GetValue("Name", string.Empty);
            string informationSystemDescription = informationSystemSection.GetValue("Description", string.Empty);

            IConfigurationSection elasticSearchSection = Configuration.GetSection("ElasticSearch");
            Uri    nodeAddress     = elasticSearchSection.GetValue <Uri>("Node");
            string indexName       = elasticSearchSection.GetValue <string>("IndexName");
            string indexSeparation = elasticSearchSection.GetValue <string>("IndexSeparationPeriod");
            int    maximumRetries  = elasticSearchSection.GetValue <int>("MaximumRetries");
            int    maxRetryTimeout = elasticSearchSection.GetValue <int>("MaxRetryTimeout");

            IConfigurationSection applicationSection = Configuration.GetSection("Application");
            bool waitAfterFinish = applicationSection.GetValue("WaitAfterFinish", false);

            if (string.IsNullOrEmpty(eventLogPath))
            {
                Console.WriteLine("Не указан каталог с файлами данных журнала регистрации.");
                Console.WriteLine("Для выхода нажмите любую клавишу...");
                Console.Read();
                return;
            }

            Console.WriteLine();
            Console.WriteLine();

            ConnectionSettings elasticSettings = new ConnectionSettings(nodeAddress)
                                                 .DefaultIndex(indexName)
                                                 .MaximumRetries(maximumRetries)
                                                 .MaxRetryTimeout(TimeSpan.FromSeconds(maxRetryTimeout));

            using (EventLogExportMaster exporter = new EventLogExportMaster())
            {
                exporter.SetEventLogPath(eventLogPath);

                EventLogOnElasticSearch target = new EventLogOnElasticSearch(elasticSettings, portion);
                target.SetInformationSystem(new InformationSystemsBase()
                {
                    Name        = informationSystemName,
                    Description = informationSystemDescription
                });
                target.SetIndexName(indexName);
                target.SetIndexSeparationPeriod(indexSeparation);
                exporter.SetTarget(target);

                exporter.BeforeExportData  += BeforeExportData;
                exporter.AfterExportData   += AfterExportData;
                exporter.OnErrorExportData += OnErrorExportData;

                _beginPortionExport = DateTime.Now;
                if (useWatchMode)
                {
                    while (true)
                    {
                        if (Console.KeyAvailable)
                        {
                            if (Console.ReadKey().KeyChar == 'q')
                            {
                                break;
                            }
                        }

                        while (exporter.NewDataAvailable())
                        {
                            exporter.SendData();
                        }
                        Thread.Sleep(watchPeriodSecondsMs);
                    }
                }
                else
                {
                    while (exporter.NewDataAvailable())
                    {
                        exporter.SendData();
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine();
            if (waitAfterFinish)
            {
                Console.WriteLine("Для выхода нажмите любую клавишу...");
                Console.Read();
            }
        }