Beispiel #1
0
        public RavenConfiguration(string resourceName, ResourceType resourceType, string customConfigPath = null)
        {
            ResourceName = resourceName;
            ResourceType = resourceType;

            _configBuilder = new ConfigurationBuilder();
            AddEnvironmentVariables();
            AddJsonConfigurationVariables(customConfigPath);

            Settings = _configBuilder.Build();

            Core = new CoreConfiguration();

            Http             = new HttpConfiguration();
            Replication      = new ReplicationConfiguration();
            Cluster          = new ClusterConfiguration();
            Etl              = new EtlConfiguration();
            Storage          = new StorageConfiguration();
            Security         = new SecurityConfiguration();
            PerformanceHints = new PerformanceHintsConfiguration();
            Indexing         = new IndexingConfiguration(this);
            Monitoring       = new MonitoringConfiguration();
            Queries          = new QueryConfiguration();
            Patching         = new PatchingConfiguration();
            Logs             = new LogsConfiguration();
            Server           = new ServerConfiguration();
            Testing          = new TestingConfiguration();
            Databases        = new DatabaseConfiguration();
            Memory           = new MemoryConfiguration();
            Studio           = new StudioConfiguration();
            Licensing        = new LicenseConfiguration();
            Tombstones       = new TombstoneConfiguration();
            Subscriptions    = new SubscriptionConfiguration();
        }
Beispiel #2
0
        /// <summary>
        /// Store the passed through logger config file to the current parameter and then update the settings.
        /// </summary>
        public void SetLogsConfiguration(LogsConfiguration logsConfiguration)
        {
            _logsConfiguration = logsConfiguration;

            SetLogLevel(_logsConfiguration.LogDetail);
            SetLogFileType(_logsConfiguration.LogFileType);
            SetLogLife(_logsConfiguration.LogLife);
        }
Beispiel #3
0
        private RavenConfiguration(string resourceName, ResourceType resourceType, string customConfigPath = null, bool skipEnvironmentVariables = false)
        {
            _logger = LoggingSource.Instance.GetLogger <RavenConfiguration>(resourceName);

            ResourceName      = resourceName;
            ResourceType      = resourceType;
            _customConfigPath = customConfigPath;
            PathSettingBase <string> .ValidatePath(_customConfigPath);

            _configBuilder = new ConfigurationBuilder();
            if (skipEnvironmentVariables == false)
            {
                AddEnvironmentVariables();
            }
            AddJsonConfigurationVariables(customConfigPath);

            Settings = _configBuilder.Build();

            Core = new CoreConfiguration();

            Http             = new HttpConfiguration();
            Replication      = new ReplicationConfiguration();
            Cluster          = new ClusterConfiguration();
            Etl              = new EtlConfiguration();
            Storage          = new StorageConfiguration();
            Security         = new SecurityConfiguration();
            Backup           = new BackupConfiguration();
            PerformanceHints = new PerformanceHintsConfiguration();
            Indexing         = new IndexingConfiguration(this);
            Monitoring       = new MonitoringConfiguration();
            Queries          = new QueryConfiguration();
            Patching         = new PatchingConfiguration();
            Logs             = new LogsConfiguration();
            Server           = new ServerConfiguration();
            Embedded         = new EmbeddedConfiguration();
            Databases        = new DatabaseConfiguration(Storage.ForceUsing32BitsPager);
            Memory           = new MemoryConfiguration();
            Studio           = new StudioConfiguration();
            Licensing        = new LicenseConfiguration();
            Tombstones       = new TombstoneConfiguration();
            Subscriptions    = new SubscriptionsConfiguration();
            TransactionMergerConfiguration = new TransactionMergerConfiguration(Storage.ForceUsing32BitsPager);
            Notifications = new NotificationsConfiguration();
            Updates       = new UpdatesConfiguration();
            Migration     = new MigrationConfiguration();
            Integrations  = new IntegrationsConfiguration();
        }
Beispiel #4
0
        public static void AddException(Exception exception, LogsConfiguration configuration, string aditionalInformation = "")
        {
            var type = exception.GetType().Name;

            Files.CreateDirectory(configuration.ExceptionsLogsFolder);
            var fileContent = new List <string>();

            if (!aditionalInformation.isNullOrEmpty())
            {
                fileContent.Add($"Mensagem: {exception.Message}");
            }
            fileContent.Add($"ExceptionMessage: {exception.Message}");
            fileContent.Add($"InnerException: {exception.InnerException}");
            fileContent.Add($"StackTrace: {exception.StackTrace}");

            File.WriteAllLines($"{configuration.ExceptionsLogsFolder}/{DateTime.Now.ToString("yyyyMM_ddHHmmss", CultureInfo.InvariantCulture)}{type}.log", fileContent);
        }
Beispiel #5
0
        /// <summary>
        /// Using the location of the configuration file, check to see if the file already exists.
        /// If it does exist then, deserialize the file with an XML serializer and then store the config file in this service.
        /// Otherwise just create a new default logs configuration.
        /// </summary>
        private void LoadConfigFile()
        {            
            LogsConfiguration logsConfiguration = null;

            if (!File.Exists(_configFileLocation))
            {
                File.Create(_configFileLocation).Dispose();
                logsConfiguration = CreateNewLogConfiguration();
            }
            else
            {
                FileStream readFileStream = null;

                try
                {
                    using (readFileStream = File.OpenRead(_configFileLocation))
                    {
                        var hierarchySerializer = new XmlSerializer(typeof(LogsConfiguration));

                        // Try to deserialize the config file as a Logger config. If this does not succeed then create a new logger config.
                        logsConfiguration = hierarchySerializer.Deserialize(readFileStream) as LogsConfiguration;
                    }
                }
                catch (InvalidOperationException ioe)
                {
                    AddLogEntry("New log configuration has been created.", ioe);
                    logsConfiguration = CreateNewLogConfiguration();
                }
                catch (Exception ex)
                {
                    AddLogEntry("An error occured when loading the logs configuration file..", ex);
                }
                finally
                {
                    readFileStream?.Close();
                }
            }

            SetLogsConfiguration(logsConfiguration);
        }
Beispiel #6
0
 private Task ValidateLogsAsync(
     DiagnosticPortConnectionMode mode,
     LogsConfiguration configuration,
     Func <ChannelReader <LogEntry>, Task> callback,
     LogFormat logFormat)
 {
     return(ScenarioRunner.SingleTarget(
                _outputHelper,
                _httpClientFactory,
                mode,
                TestAppScenarios.Logger.Name,
                appValidate: async(runner, client) =>
                await ValidateResponseStream(
                    runner,
                    client.CaptureLogsAsync(
                        await runner.ProcessIdTask,
                        CommonTestTimeouts.LogsDuration,
                        configuration,
                        logFormat),
                    callback,
                    logFormat)));
 }
Beispiel #7
0
 public Logs(LogsConfiguration configuration, EnumProcessType processType)
 {
     Log            = new List <LogModel>();
     _configuration = configuration;
     ProcessType    = processType;
 }
 /// <summary>
 /// POST /logs/{pid}?durationSeconds={duration}
 /// </summary>
 public static async Task <ResponseStreamHolder> CaptureLogsAsync(this ApiClient client, int pid, TimeSpan duration, LogsConfiguration configuration, TimeSpan timeout, LogFormat logFormat)
 {
     using CancellationTokenSource timeoutSource = new(timeout);
     return(await client.CaptureLogsAsync(pid, duration, configuration, logFormat, timeoutSource.Token));
 }
 /// <summary>
 /// POST /logs?pid={pid}&durationSeconds={duration}
 /// </summary>
 public static Task <ResponseStreamHolder> CaptureLogsAsync(this ApiClient client, int pid, TimeSpan duration, LogsConfiguration configuration, LogFormat logFormat)
 {
     return(client.CaptureLogsAsync(pid, duration, configuration, TestTimeouts.HttpApi, logFormat));
 }
        private async Task ValidateLogsActionAsync(
            LogsConfiguration configuration,
            Func <ChannelReader <LogEntry>, Task> callback,
            LogFormat logFormat,
            TargetFrameworkMoniker tfm)
        {
            using TemporaryDirectory tempDirectory = new(_outputHelper);

            await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
            {
                rootOptions.AddFileSystemEgress(ActionTestsConstants.ExpectedEgressProvider, tempDirectory.FullName);

                rootOptions.CreateCollectionRule(DefaultRuleName)
                .AddCollectLogsAction(ActionTestsConstants.ExpectedEgressProvider, options =>
                {
                    options.Duration      = CommonTestTimeouts.LogsDuration;
                    options.FilterSpecs   = configuration.FilterSpecs;
                    options.DefaultLevel  = configuration.LogLevel;
                    options.Format        = logFormat;
                    options.UseAppFilters = configuration.UseAppFilters;
                })
                .SetStartupTrigger();
            }, async host =>
            {
                CollectLogsOptions options = ActionTestsHelper.GetActionOptions <CollectLogsOptions>(host, DefaultRuleName);

                // This is reassigned here due to a quirk in which a null value in the dictionary has its key removed, thus causing LogsDefaultLevelFallbackActionTest to fail. By reassigning here, any keys with null values are maintained.
                options.FilterSpecs = configuration.FilterSpecs;

                ICollectionRuleActionFactoryProxy factory;
                Assert.True(host.Services.GetService <ICollectionRuleActionOperations>().TryCreateFactory(KnownCollectionRuleActions.CollectLogs, out factory));

                using CancellationTokenSource endpointTokenSource = new CancellationTokenSource(CommonTestTimeouts.LogsTimeout);

                EndpointInfoSourceCallback endpointInfoCallback = new(_outputHelper);
                await using ServerSourceHolder sourceHolder     = await _endpointUtilities.StartServerAsync(endpointInfoCallback);

                AppRunner runner    = _endpointUtilities.CreateAppRunner(sourceHolder.TransportName, tfm);
                runner.ScenarioName = TestAppScenarios.Logger.Name;

                Task <IEndpointInfo> newEndpointInfoTask = endpointInfoCallback.WaitAddedEndpointInfoAsync(runner, CommonTestTimeouts.StartProcess);

                await runner.ExecuteAsync(async() =>
                {
                    IEndpointInfo endpointInfo = await newEndpointInfoTask;

                    ICollectionRuleAction action = factory.Create(endpointInfo, options);

                    using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(CommonTestTimeouts.LogsTimeout);

                    CollectionRuleActionResult result;
                    try
                    {
                        await action.StartAsync(cancellationTokenSource.Token);

                        await runner.SendCommandAsync(TestAppScenarios.Logger.Commands.StartLogging);

                        result = await action.WaitForCompletionAsync(cancellationTokenSource.Token);
                    }
                    finally
                    {
                        await Tools.Monitor.DisposableHelper.DisposeAsync(action);
                    }

                    string egressPath = ActionTestsHelper.ValidateEgressPath(result);

                    using FileStream logsStream = new(egressPath, FileMode.Open, FileAccess.Read);
                    Assert.NotNull(logsStream);

                    await LogsTestUtilities.ValidateLogsEquality(logsStream, callback, logFormat, _outputHelper);
                });
            });
        }
 protected void RegisterLogs(LogsConfiguration configuration) => Services.AddSingleton <Logs>(provider => new Logs(configuration, ProcessType));
 private void connectModel()
 {
     logsConfigurationModel = new LogsConfiguration();
     encrypt = new Encrypt();
 }
Beispiel #13
0
        private Task <ResponseStreamHolder> CaptureLogsAsync(string processQuery, TimeSpan duration, LogsConfiguration configuration, LogFormat logFormat, CancellationToken token)
        {
            string json = JsonSerializer.Serialize(configuration, DefaultJsonSerializeOptions);

            return(CaptureLogsAsync(
                       HttpMethod.Post,
                       CreateLogsUriString(processQuery, duration, logLevel: null),
                       new StringContent(json, Encoding.UTF8, ContentTypes.ApplicationJson),
                       logFormat,
                       token));
        }
Beispiel #14
0
 /// <summary>
 /// POST /logs?pid={pid}&durationSeconds={duration}
 /// </summary>
 public Task <ResponseStreamHolder> CaptureLogsAsync(int pid, TimeSpan duration, LogsConfiguration configuration, LogFormat logFormat, CancellationToken token)
 {
     return(CaptureLogsAsync(GetProcessQuery(pid: pid), duration, configuration, logFormat, token));
 }