/* * Greenshot - a free and open source screenshot tool * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * * For more information see: http://getgreenshot.org/ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ using Dapplo.Log; using log4net; namespace GreenshotJiraPlugin { /// /// Used to make Dapplo.Log, used in Dapplo.Jira, write to Log4net /// public class Log4NetLogger : AbstractLogger { private ILog GetLogger(LogSource logSource) { return logSource.SourceType != null ? LogManager.GetLogger(logSource.SourceType) : LogManager.GetLogger(logSource.Source); } /// /// Write the supplied information to a log4net.ILog /// /// LogInfo /// string /// params object[] public override void Write(LogInfo logInfo, string messageTemplate, params object[] propertyValues) { var log = GetLogger(logInfo.Source); switch (logInfo.LogLevel) { case LogLevels.Verbose: case LogLevels.Debug: if (propertyValues != null) log.DebugFormat(messageTemplate, propertyValues); else log.Debug(messageTemplate); break; case LogLevels.Error: if (propertyValues != null) log.ErrorFormat(messageTemplate, propertyValues); else log.Error(messageTemplate); break; case LogLevels.Fatal: if (propertyValues != null) log.FatalFormat(messageTemplate, propertyValues); else log.Fatal(messageTemplate); break; case LogLevels.Info: if (propertyValues != null) log.InfoFormat(messageTemplate, propertyValues); else log.Info(messageTemplate); break; case LogLevels.Warn: if (propertyValues != null) log.WarnFormat(messageTemplate, propertyValues); else log.Warn(messageTemplate); break; } } /// /// Make sure there are no newlines passed /// /// /// /// public override void WriteLine(LogInfo logInfo, string messageTemplate, params object[] logParameters) { Write(logInfo, messageTemplate, logParameters); } /// /// Test if a certain LogLevels enum is enabled /// /// LogLevels value /// LogSource to check for /// bool true if the LogLevels enum is enabled public override bool IsLogLevelEnabled(LogLevels level, LogSource logSource = null) { var log = GetLogger(logSource); switch (level) { case LogLevels.Verbose: case LogLevels.Debug: return log.IsDebugEnabled; case LogLevels.Error: return log.IsErrorEnabled; case LogLevels.Fatal: return log.IsFatalEnabled; case LogLevels.Info: return log.IsInfoEnabled; case LogLevels.Warn: return log.IsWarnEnabled; } return false; } } }