static McsLogger()
        {
            string logDestinationType  = ConfigurationManager.AppSettings["McsFileLogDestinationTypes"] ?? "";
            string logFolderLocation   = ConfigurationManager.AppSettings["LogFolderLocation"] ?? ".\\Logs\\";
            string logConnectionString = ConfigurationManager.ConnectionStrings["LogConnection"].ConnectionString ?? "";
            string logBatchSize        = ConfigurationManager.AppSettings["LogBatchSize"] ?? "1";

            if (!int.TryParse(logBatchSize, out var batchSize))
            {
                batchSize = 1;
            }

            var logToFile = logDestinationType.ToUpper().Contains("FILE");
            var logToSQL  = logDestinationType.ToUpper().Contains("SQL");

            if (logToSQL && logToFile)
            {
                FileSqlLogBuilder.BuildLogger(ref _perfLogger, ref _usageLogger, ref _errorLogger, ref _diagnosticLogger, logFolderLocation, logConnectionString, batchSize);
            }
            else if (logToFile)
            {
                FileLogBuilder.BuildLogger(ref _perfLogger, ref _usageLogger, ref _errorLogger, ref _diagnosticLogger, logFolderLocation);
            }
            else if (logToSQL)
            {
                SqlLogBuilder.BuildLogger(ref _perfLogger, ref _usageLogger, ref _errorLogger, ref _diagnosticLogger, logConnectionString, batchSize);
            }
        }
Esempio n. 2
0
        static McsLogger()
        {
            if (!bool.TryParse(Environment.GetEnvironmentVariable("MCS_ENABLE_DIAGNOSTICS"), out var enableDiagnostics))
            {
                enableDiagnostics = false;
            }
            if (!int.TryParse(Environment.GetEnvironmentVariable("MCS_LOG_BATCH_SIZE"), out var batchSize))
            {
                batchSize = 1;
            }

            _settings = new McsLoggingSettings()
            {
                EnableDiagnostics      = enableDiagnostics,
                LogBatchSize           = batchSize,
                LogConnection          = Environment.GetEnvironmentVariable("MCS_LOG_CONNECTION"),
                LogFolderLocation      = Environment.GetEnvironmentVariable("MCS_LOG_FOLDER_LOCATION"),
                McsLogDestinationTypes = Environment.GetEnvironmentVariable("MCS_LOG_DESTINATION_TYPES")
            };

            var logToFile = _settings.McsLogDestinationTypes.ToUpper().Contains("FILE");
            var logToSQL  = _settings.McsLogDestinationTypes.ToUpper().Contains("SQL");

            if (logToSQL && logToFile)
            {
                FileSqlLogBuilder.BuildLogger(ref _perfLogger, ref _usageLogger, ref _errorLogger, ref _diagnosticLogger, _settings);
            }
            else if (logToFile)
            {
                FileLogBuilder.BuildLogger(ref _perfLogger, ref _usageLogger, ref _errorLogger, ref _diagnosticLogger, _settings);
            }
            else if (logToSQL)
            {
                SqlLogBuilder.BuildLogger(ref _perfLogger, ref _usageLogger, ref _errorLogger, ref _diagnosticLogger, _settings);
            }
        }