private bool SetLoggerConfigurationParameters()
        {
            var logger         = this.Logger;
            var bridgeOptions  = this.BridgeOptions;
            var assemblyConfig = this.TranslatorConfiguration;

            if (bridgeOptions.NoLoggerSetUp)
            {
                return(true);
            }

            logger.Info("Applying logger configuration parameters...");

            logger.Name = bridgeOptions.Name;

            if (!string.IsNullOrEmpty(logger.Name))
            {
                logger.Info("Logger name: " + logger.Name);
            }

            var loggerLevel = assemblyConfig.Logging.Level ?? LoggerLevel.None;

            logger.Info("Logger level: " + loggerLevel);

            if (loggerLevel <= LoggerLevel.None)
            {
                logger.Info("To enable further logging use configuration setting \"logging\" in bridge.json. See http://bridge.net/docs/global-configuration/#logging");
            }

            try
            {
                logger.LoggerLevel = loggerLevel;

                logger.Info("Read config file: " + AssemblyConfigHelper.ConfigToString(assemblyConfig));

                logger.BufferedMode = false;

                if (bridgeOptions.NoTimeStamp.HasValue)
                {
                    logger.UseTimeStamp = !bridgeOptions.NoTimeStamp.Value;
                }
                else if (assemblyConfig.Logging.TimeStamps.HasValue)
                {
                    logger.UseTimeStamp = assemblyConfig.Logging.TimeStamps.Value;
                }
                else
                {
                    logger.UseTimeStamp = true;
                }

                var fileLoggerWriter = logger.GetFileLogger();

                if (fileLoggerWriter != null)
                {
                    var logFileFolder = assemblyConfig.Logging.Folder;
                    if (string.IsNullOrWhiteSpace(logFileFolder))
                    {
                        logFileFolder = this.GetOutputFolder(false, false);
                    }
                    else if (!Path.IsPathRooted(logFileFolder))
                    {
                        logFileFolder = Path.Combine(this.GetOutputFolder(true, false), logFileFolder);
                    }

                    fileLoggerWriter.SetParameters(logFileFolder, assemblyConfig.Logging.FileName, assemblyConfig.Logging.MaxSize);
                }

                logger.Flush();

                logger.Info("Setting logger configuration parameters done");

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not read configuration: " + ex.ToString());
            }

            return(false);
        }
Exemple #2
0
        private void SetLoggerConfigurationParameters()
        {
            var logger         = this.Logger;
            var bridgeOptions  = this.BridgeOptions;
            var assemblyConfig = this.TranslatorConfiguration;

            if (bridgeOptions.NoLoggerSetUp)
            {
                return;
            }

            logger.Trace("Applying logger configuration parameters...");

            logger.Name = bridgeOptions.Name;

            if (!string.IsNullOrEmpty(logger.Name))
            {
                logger.Trace("Logger name: " + logger.Name);
            }

            var loggerLevel = assemblyConfig.Logging.Level ?? LoggerLevel.None;

            logger.Trace("Logger level: " + loggerLevel);

            if (loggerLevel <= LoggerLevel.None)
            {
                logger.Info("    To enable detailed logging, configure \"logging\" in bridge.json.");
                logger.Info("    https://github.com/bridgedotnet/Bridge/wiki/global-configuration#logging");
            }

            logger.LoggerLevel = loggerLevel;

            logger.Trace("Read config file: " + AssemblyConfigHelper.ConfigToString(assemblyConfig));

            logger.BufferedMode = false;

            if (bridgeOptions.NoTimeStamp.HasValue)
            {
                logger.UseTimeStamp = !bridgeOptions.NoTimeStamp.Value;
            }
            else if (assemblyConfig.Logging.TimeStamps.HasValue)
            {
                logger.UseTimeStamp = assemblyConfig.Logging.TimeStamps.Value;
            }
            else
            {
                logger.UseTimeStamp = true;
            }

            var fileLoggerWriter = logger.GetFileLogger();

            if (fileLoggerWriter != null)
            {
                string logFileFolder = GetLoggerFolder(assemblyConfig);

                fileLoggerWriter.SetParameters(logFileFolder, assemblyConfig.Logging.FileName, assemblyConfig.Logging.MaxSize);
            }

            logger.Flush();

            logger.Trace("Setting logger configuration parameters done");
        }