本文整理汇总了C#中LoggingLevel类的典型用法代码示例。如果您正苦于以下问题:C# LoggingLevel类的具体用法?C# LoggingLevel怎么用?C# LoggingLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LoggingLevel类属于命名空间,在下文中一共展示了LoggingLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogException
public void LogException(MethodBase methodBase, Exception err, LoggingLevel exceptionLevel)
{
ILog logger = LogManager.GetLogger(methodBase.DeclaringType);
if (ShouldLog(logger, exceptionLevel, methodBase)) {
exceptionLogger.LogException(err, false, methodBase.DeclaringType);
}
}
示例2: Create
/// <summary>
/// Parses the XML of the configuration section.
/// </summary>
/// <param name="parent">The configuration settings in a corresponding parent configuration section.</param>
/// <param name="configContext">An HttpConfigurationContext when Create is called from the ASP.NET configuration system. Otherwise, this parameter is reserved and is a null reference.</param>
/// <param name="section">The XmlNode that contains the configuration information from the configuration file. Provides direct access to the XML contents of the configuration section.</param>
/// <returns>A configuration object.</returns>
public object Create(object parent, object configContext, XmlNode section)
{
XmlElement loggingElement = (XmlElement) section;
if (loggingElement.HasAttribute("LoggingLevel"))
{
loggingLevel = (LoggingLevel) Enum.Parse(typeof(LoggingLevel), loggingElement.GetAttribute("LoggingLevel"), true);
}
else
{
loggingLevel = LoggingLevel.Off;
}
if (loggingElement.HasChildNodes)
{
foreach (XmlElement element in loggingElement.SelectNodes("logger"))
{
string typeName = element.GetAttribute("type");
// Use reflection to create an instance of the configured Logger instance
Type type = Type.GetType(typeName);
LoggerBase logger = (LoggerBase) type.Assembly.CreateInstance(type.FullName);
logger.Configure(element);
loggers.Add(logger);
}
}
return this;
}
示例3: LogItem
/// <summary>
/// Initializes a new LogItem class
/// </summary>
/// <param name="message">Message to log</param>
/// <param name="exception">Exception to log</param>
/// <param name="level">Message level</param>
public LogItem(string message, Exception exception = null, LoggingLevel level = LoggingLevel.Info)
{
Message = message;
Exception = exception;
Created = DateTime.UtcNow;
Level = level;
}
示例4: LogEntry
public override void LogEntry(string source, string message, LoggingLevel loggingLevel)
{
if (EventLog.Exists(logName))
{
StringWriter writer = new StringWriter();
writer.WriteLine("Source: " + source);
writer.WriteLine("Message: " + message);
message = writer.ToString();
switch (loggingLevel)
{
case LoggingLevel.Error:
EventLog.WriteEntry(logName, message, EventLogEntryType.Error);
break;
case LoggingLevel.Warning:
EventLog.WriteEntry(logName, message, EventLogEntryType.Warning);
break;
case LoggingLevel.Information:
case LoggingLevel.Verbose:
EventLog.WriteEntry(logName, message, EventLogEntryType.Information);
break;
default:
break;
}
}
else
{
StringWriter writer = new StringWriter();
writer.WriteLine("Entries cannot be written to the " + logName + " log because it does not exist.");
writer.WriteLine("Source: " + source);
writer.WriteLine("Message: " + message);
throw new InvalidOperationException(writer.ToString());
}
}
示例5: CommonServiceException
/// <summary>
/// Initializes a new instance of the
/// <see cref="T:WebApplications.Utilities.Logging.LoggingException" /> class.
/// </summary>
/// <param name="level">The log level.</param>
/// <param name="resource">The resource expression, e.g. ()=> Resources.Log_Message.</param>
/// <param name="parameters">The parameters.</param>
internal CommonServiceException(
LoggingLevel level,
[CanBeNull] Expression<Func<string>> resource,
[CanBeNull] params object[] parameters)
: base(level, resource, parameters)
{
}
示例6: WriteLog
public static void WriteLog(string messageFormat, LoggingLevel loggingLevel = LoggingLevel.Default, params object[] args) {
//WriteLog(String.Format(message, args), loggingLevel);
#if DEBUG
lock (lockFlag) {
#endif
{
string message = messageFormat;
bool isNotMessageFormatted = true;
try {
message = string.Format(messageFormat, args);
isNotMessageFormatted = false;
}
catch { }
WriteConsole(message);
if (IsLoggingToFileEnabled) {
if (message.Length < 20 * 1024) {
LogToFile(message);
}
}
}
#if DEBUG
}
#endif
}
示例7: DatabaseSchemaException
/// <summary>
/// Initializes a new instance of the <see cref="LoggingException" /> class.
/// </summary>
/// <param name="level">The severity of the exception being logged.</param>
/// <param name="resource">The resource expression, e.g. ()=> Resources.Log_Message.</param>
/// <param name="parameters">The parameters.</param>
public DatabaseSchemaException(
LoggingLevel level,
[CanBeNull] Expression<Func<string>> resource,
[CanBeNull] params object[] parameters)
: base(level, resource, parameters)
{
}
示例8: Log
public static void Log(LoggingLevel level, Exception exception)
{
if (exception != null)
{
Log(level, exception.ToString());
}
}
示例9: Log
protected override void Log(LoggingLevel level, object sender, object message, object verbose, Exception t)
{
if (!(IsVerboseEnabled))
verbose = "";
WriteLine(level, message.ToString() + "; " + t.ToString() + "; " + verbose, sender); // do not localize
}
示例10: Log
public void Log(Exception exception, LoggingLevel loggingLevel, [CallerMemberName] string memberName = "", [CallerFilePath] string classFilePath = "", [CallerLineNumber]int line = 0)
{
if (exception != null)
{
Log(exception.Message, loggingLevel, memberName, classFilePath, line);
}
}
示例11: Log
/// <summary>
/// Log a message
/// </summary>
/// <param name="level"></param>
/// <param name="function"></param>
/// <param name="message"></param>
/// <param name="ex"></param>
public static void Log(LoggingLevel level, string function, string message, Exception ex)
{
if (level >= minLevel)
{
// log message to file, email, pager
}
}
示例12: Logger
public Logger(string path, LoggingLevel level, params TextWriter[] otherOutputs)
{
_path = path;
_level = level;
_otherOutputs = otherOutputs;
_messageBuffer = new List<string>();
}
示例13: LogEntry
public void LogEntry(MethodBase methodBase, object[] argumentValues, LoggingLevel entryLevel)
{
var logger = LogManager.GetLogger(methodBase.DeclaringType);
if (this.ShouldLog(logger, entryLevel, methodBase))
{
var logMessage = new StringBuilder();
logMessage.Append(string.Format("{0}(", methodBase.Name));
var parameterInfos = methodBase.GetParameters();
if (argumentValues != null && parameterInfos != null)
{
for (var i = 0; i < argumentValues.Length; i++)
{
if (i > 0)
{
logMessage.Append(" ");
}
logMessage.Append(string.Format("{0}:[{1}]", parameterInfos[i].Name, argumentValues[i]));
}
}
logMessage.Append(")");
logger.Log(entryLevel, logMessage.ToString());
}
}
示例14: LogMessage
private static void LogMessage(object sender, LoggingLevel loggingLevel, string message, params object[] args)
{
try
{
string loggerName = "Main";
if (sender != null)
{
loggerName = sender.GetType().Name;
}
message = string.Format(message, args);
Logger logger = LogManager.GetLogger(loggerName);
switch (loggingLevel)
{
case LoggingLevel.Error: logger.Error(message); break;
case LoggingLevel.Warning: logger.Warn(message); break;
case LoggingLevel.Info: logger.Info(message); break;
case LoggingLevel.Critical: logger.Fatal(message); break;
default: logger.Debug(message); break;
}
}
catch (Exception ex)
{
Trace.WriteLine(string.Format("NLog exception: {0}, {1}", ex.Message, ex.StackTrace));
}
}
示例15: ShouldLog
private bool ShouldLog(ILog logger, LoggingLevel loggingLevel, MethodBase methodBase)
{
if (methodBase != null && methodBase.Name != null) {
return logger.IsEnabledFor(loggingLevel);
}
return false;
}