Esempio n. 1
0
        public void OutputAction(IDictionary <string, object> obj)
        {
            if (_firstEntry)
            {
                _logger.Log(LogLevel.INFORMATION, "Writing events to log...");
                _firstEntry = false;
            }

            try
            {
                // Serializing data
                var json = JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });


                // Writing event to log
                _eventLog.WriteEvent(new EventInstance(_eventId, 0, EventLogEntryType.Information), json);
            }
            catch (Exception ex)
            {
                OutputError(ex);
            }
        }
Esempio n. 2
0
        public EventLogOutput(BaseLogger logger, string logName, string sourceName)
        {
            _logger     = logger;
            _logName    = logName;
            _source     = sourceName;
            _eventLog   = new EventLog(logName);
            _eventId    = 6;
            _firstEntry = true;

            try
            {
                // Create the source, if it does not already exist.
                if (!EventLog.SourceExists(_source))
                {
                    //An event log source should not be created and immediately used.
                    //There is a latency time to enable the source, will have to sleep
                    //before writing events to log
                    EventLog.CreateEventSource(_source, _logName);
                    _logger.Log(LogLevel.INFORMATION, "CreatedEventSource");
                    _logger.Log(LogLevel.INFORMATION, "Sleeping to let the machine catch up...");
                    Thread.Sleep(10000);
                }

                // Setting event source
                _eventLog.Source = _source;
            }
            catch (Exception ex)
            {
                OutputError(ex);
            }
        }
Esempio n. 3
0
        public AdxOutput(
            BaseLogger logger,
            string authority,
            string appclientId,
            string appKey,
            string cluster,
            string database,
            string table,
            bool createOrResetTable = false,
            bool directIngest       = false)
        {
            _logger = logger;

            _table = table;
            _createOrResetTable = createOrResetTable;

            _batchSize       = 10000;
            _flushDuration   = TimeSpan.FromMilliseconds(5);
            _lastUploadTime  = DateTime.UtcNow;
            _initializeTable = false;
            _nextBatch       = new List <IDictionary <string, object> >();

            Completed = new AutoResetEvent(false);

            // Setting up kusto connection
            if (!string.IsNullOrEmpty(authority))
            {
                if (!string.IsNullOrEmpty(appclientId) && !string.IsNullOrEmpty(appKey))
                {
                    kscbIngest = new KustoConnectionStringBuilder($"https://ingest-{cluster}", database).WithAadApplicationKeyAuthentication(appclientId, appKey, authority);
                    kscbAdmin  = new KustoConnectionStringBuilder($"https://{cluster}", database).WithAadApplicationKeyAuthentication(appclientId, appKey, authority);
                }
                else
                {
                    kscbIngest = new KustoConnectionStringBuilder($"https://ingest-{cluster}", database).WithAadUserPromptAuthentication(authority);
                    kscbAdmin  = new KustoConnectionStringBuilder($"https://{cluster}", database).WithAadUserPromptAuthentication(authority);
                }
            }

            if (kscbAdmin != null)
            {
                _ingestionProperties = new KustoIngestionProperties(kscbIngest.InitialCatalog, table);

                if (directIngest)
                {
                    _ingestClient = KustoIngestFactory.CreateDirectIngestClient(this.kscbAdmin);
                }
                else
                {
                    _ingestClient = KustoIngestFactory.CreateQueuedIngestClient(kscbIngest);
                }
            }
            else
            {
                _logger.Log(LogLevel.ERROR, "ERROR getting ADX connection strings. Please double check the information provided.");
                _error = true;
            }
        }
Esempio n. 4
0
        public BlobOutput(BaseLogger logger, string connectionString, string containerName)
        {
            _logger = logger;

            _batchSize      = 10000;
            _flushDuration  = TimeSpan.FromMilliseconds(5);
            _lastUploadTime = DateTime.UtcNow;
            _nextBatch      = new List <IDictionary <string, object> >();

            Completed = new AutoResetEvent(false);

            if (!string.IsNullOrEmpty(connectionString) && !string.IsNullOrEmpty(containerName))
            {
                _blobServiceClient   = new BlobServiceClient(connectionString);
                _blobContainerClient = _blobServiceClient.GetBlobContainerClient(containerName);
                _blobContainerClient.CreateIfNotExists();
            }
            else
            {
                _logger.Log(LogLevel.ERROR, $"ERROR setting up connection to Blob. Please double check the information provided.");
                _error = true;
            }
        }
Esempio n. 5
0
 public void OutputError(Exception ex)
 {
     _running = false;
     _logger.Log(LogLevel.ERROR, ex);
 }
Esempio n. 6
0
 public void OutputError(Exception ex)
 {
     _error = true;
     _logger.Log(LogLevel.ERROR, ex);
 }