private void ExportToElasticSearch(EventLogExportSettingsForElasticSearch eventLogSettings) { ConnectionSettings elasticSettings = new ConnectionSettings(eventLogSettings.NodeAddress) .DefaultIndex(eventLogSettings.IndexName) .MaximumRetries(eventLogSettings.MaximumRetries) .MaxRetryTimeout(TimeSpan.FromSeconds(eventLogSettings.MaxRetryTimeout)); EventLogOnElasticSearch target = new EventLogOnElasticSearch(elasticSettings, eventLogSettings.Portion); target.SetInformationSystem(new InformationSystemsBase() { Name = eventLogSettings.InforamtionSystemName, Description = eventLogSettings.InforamtionSystemDescription }); target.SetIndexName(eventLogSettings.IndexName); target.SetIndexSeparationPeriod(eventLogSettings.IndexSeparation); ElasticClient client = new ElasticClient(elasticSettings); var allIndices = client.Indices.Get(new GetIndexRequest(Indices.All)); foreach (var indexInfo in allIndices.Indices) { if (indexInfo.Key.Name.StartsWith(eventLogSettings.IndexName)) { client.Indices.Delete(indexInfo.Key.Name); } } ExportHelperForElasticSearch.ExportToTargetStorage(eventLogSettings, target); Thread.Sleep(30000); long rowsInES = 0; string indexNameLGF_WithData = $"{eventLogSettings.IndexName}-logdata"; var allIndicesCheckData = client.Indices.Get(new GetIndexRequest(Indices.All)); foreach (var indexInfo in allIndicesCheckData.Indices) { if (indexInfo.Key.Name.StartsWith(indexNameLGF_WithData)) { var countResponse = client.Count <LogDataElement>(c => c .Index(indexInfo.Key.Name)); rowsInES += countResponse.Count; } } long rowsInSourceFiles; using (EventLogReader reader = EventLogReader.CreateReader(eventLogSettings.EventLogPath)) rowsInSourceFiles = reader.Count(); Assert.NotEqual(0, rowsInSourceFiles); Assert.NotEqual(0, rowsInES); Assert.Equal(rowsInSourceFiles, rowsInES); }
public static void ExportToTargetStorage(EventLogExportSettingsForElasticSearch 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(); } } }