Example #1
0
        private void Log(LogSettings settings)
        {
            // Only log if the log level is appropriate
            var level = LogPluginConstants.LevelFor(LogLevel);

            // Validate: log.debug but level is Warn
            if (level < settings.LogLevelValue)
            {
                return;
            }

            // Good to log.
            string message = LogHelper.BuildMessage(ParamList);

            if (settings.OutputMode == LogPluginConstants.Console)
            {
                Console.WriteLine(LogLevel + " : " + message);
            }
            else if (settings.OutputMode == LogPluginConstants.Callback)
            {
                settings.Callback(level, message, null);
            }
            else if (settings.OutputMode == LogPluginConstants.File && settings.Logger != null)
            {
                settings.Logger.WriteLine(LogLevel + " : " + message);
            }
        }
Example #2
0
        private void Configure(LogSettings settings)
        {
            ExceptionHelper.NotNullType(this, this.ParamList[0], "log level not supplied", LTypes.String);
            ExceptionHelper.NotNullType(this, this.ParamList[1], "console or log not supplied", LTypes.String);

            // Param 1: Error level
            settings.LogLevelName  = ((LString)this.ParamList[0]).Value;
            settings.LogLevelValue = LogPluginConstants.LevelFor(settings.LogLevelName);

            // Param 2: Console or file?
            var output = ((LString)this.ParamList[1]).Value;

            if (string.Compare(output, "console", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                settings.OutputMode = LogPluginConstants.Console;
            }
            else if (string.Compare(output, "callback", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                settings.OutputMode = LogPluginConstants.Callback;
                settings.Callback   = Callback;
            }
            else
            {
                // Close any existing log
                Dispose(settings);
                SetupFileLog(settings);
            }
        }