本文整理汇总了C#中LoggerLevel.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LoggerLevel.ToString方法的具体用法?C# LoggerLevel.ToString怎么用?C# LoggerLevel.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LoggerLevel
的用法示例。
在下文中一共展示了LoggerLevel.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Log
/// <summary>
/// A Common method to log.
/// </summary>
/// <param name="level">The level of logging</param>
/// <param name="name">The name of the logger</param>
/// <param name="message">The Message</param>
/// <param name="exception">The Exception</param>
protected override void Log(LoggerLevel level, String name, String message, Exception exception)
{
Console.Out.WriteLine(string.Format("[{0}] '{1}' {2}", level.ToString(), name, message));
if (exception != null)
{
Console.Out.WriteLine("[{0}] '{1}' {2}: {3} {4}", level.ToString(), name, exception.GetType().FullName,
exception.Message, exception.StackTrace);
}
}
示例2: Output
// ----------------------------------------------------------------------
protected override void Output( LoggerLevel level, object message, Exception exception )
{
buffer.Append( level.ToString() );
buffer.Append( ": " );
buffer.AppendLine( message == null ? "null" : message.ToString() );
Output( exception );
}
示例3: Log
public void Log(String logMessage, LoggerLevel messageLevel, params ComponentType[] messageComponentTypes)
{
if (messageLevel < _logThreshholdLevel) { return; }
string date = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
string level = messageLevel == LoggerLevel.NULL ? " " : messageLevel.ToString();
string type = messageComponentTypes[0] == ComponentType.NULL ? " " : ComponentTypeUtil.GetCodeFromType(messageComponentTypes[0]);
// If no component types are specified, log everything.
if (componentTypesToLog == null || componentTypesToLog.Count == 0)
{
_streamWriter.WriteLine(date + " | " + level + " | " + type + " | " + logMessage);
_streamWriter.Flush();
return;
}
else // Else, only log messages matching one of the specified component types.
{
foreach (ComponentType componentType in messageComponentTypes)
{
if (componentTypesToLog.Contains(componentType))
{
_streamWriter.WriteLine(date + " | " + level + " | " + type + " | " + logMessage);
_streamWriter.Flush();
return;
}
}
}
}
示例4: Log
/// <summary>
/// A Common method to log.
/// </summary>
/// <param name="level">The level of logging</param>
/// <param name="name">The Log name.</param>
/// <param name="message">The Message</param>
/// <param name="exception">The Exception</param>
protected override void Log(LoggerLevel level, String name, String message, Exception exception)
{
TraceContext ctx = HttpContext.Current.Trace;
if (ctx.IsEnabled)
{
String category = String.Format("[{0}]", level.ToString());
String formattedMessage = String.Format("{0} {1}", name, message);
ctx.Write(category, formattedMessage);
if (exception != null)
{
formattedMessage = String.Format("{0}: {1} {2}Stack Trace: {3}",
exception.GetType(), exception.Message, Environment.NewLine, exception.StackTrace);
ctx.Warn(category, formattedMessage);
}
}
}
示例5: Log
/// <summary>
/// A Common method to log.
/// </summary>
/// <param name="loggerLevel">The level of logging</param>
/// <param name="loggerName">The Log name.</param>
/// <param name="message">The Message</param>
/// <param name="exception">The Exception</param>
protected override void Log(LoggerLevel loggerLevel, String loggerName, String message, Exception exception)
{
TraceContext ctx = TryToGetTraceContext();
if (ctx == null)
return;
if (ctx.IsEnabled)
{
String category = String.Format(CultureInfo.CurrentCulture, "[{0}]", loggerLevel.ToString());
String formattedMessage = String.Format(CultureInfo.CurrentCulture, "{0} {1}", loggerName, message);
ctx.Write(category, formattedMessage);
if (exception != null)
{
formattedMessage = String.Format(CultureInfo.CurrentCulture, "{0}: {1} {2}Stack Trace: {3}",
exception.GetType(), exception.Message, Environment.NewLine, exception.StackTrace);
ctx.Warn(category, formattedMessage);
}
}
}
示例6: AddLogFile
private void AddLogFile(LoggerLevel level, string message, int code)
{
if (strLogFilePath == null || strLogFilePath.Length == 0)
{
throw new ApplicationException("no log file path specified");
}
//If the log file path is not empty but the file is not available it will create it
if (false == File.Exists(strLogFilePath))
{
if (false == CheckDirectory(strLogFilePath))
{
throw new ApplicationException("problems with log file path");
}
FileStream fs = new FileStream(strLogFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
fs.Close();
}
Exception last_exception = null;
StreamWriter sw = null;
for (int timeout = 0; timeout < 30; timeout++)
{
try
{
sw = new StreamWriter(strLogFilePath, true);
if (sw != null) break;
}
catch (Exception ex)
{
last_exception = ex;
sw = null;
}
Thread.Sleep(100);
}
if (sw == null)
{
// MessageBox.Show("can't open log file: " + last_exception.Message);
throw new Exception("can't open log file: " + last_exception.Message);
}
StringBuilder line = new StringBuilder();
line.Append(DateTime.Now.ToString("u"));
line.Append(" ");
line.Append(m_source);
line.Append(" ");
line.Append(level.ToString());
line.Append(" ");
line.Append(message);
if (code != 0)
{
line.Append(" (code=");
line.Append(code.ToString());
line.Append(")");
}
sw.WriteLine(line.ToString());
sw.Flush();
sw.Close();
}
示例7: Format
// ----------------------------------------------------------------------
public static string Format( LoggerLevel value )
{
return value.ToString();
}
示例8: ValidateCall
private void ValidateCall(LoggerLevel level, String expectedMessage, Exception expectedException)
{
stream.Seek(0, SeekOrigin.Begin);
StreamReader reader = new StreamReader(stream);
String line = reader.ReadLine();
Match match = Regex.Match(line, @"^\[(?<level>[^]]+)\] '(?<name>[^']+)' (?<message>.*)$");
Assert.IsTrue(match.Success, "StreamLogger.Log did not match the format");
Assert.AreEqual(Name, match.Groups["name"].Value, "StreamLogger.Log did not write the correct Name");
Assert.AreEqual(level.ToString(), match.Groups["level"].Value, "StreamLogger.Log did not write the correct Level");
Assert.AreEqual(expectedMessage, match.Groups["message"].Value, "StreamLogger.Log did not write the correct Message");
line = reader.ReadLine();
if (expectedException == null)
{
Assert.IsNull(line);
}
else
{
match = Regex.Match(line, @"^\[(?<level>[^]]+)\] '(?<name>[^']+)' (?<type>[^:]+): (?<message>.*)$");
Assert.IsTrue(match.Success, "StreamLogger.Log did not match the format");
Assert.AreEqual(Name, match.Groups["name"].Value, "StreamLogger.Log did not write the correct Name");
Assert.AreEqual(level.ToString(), match.Groups["level"].Value, "StreamLogger.Log did not write the correct Level");
Assert.AreEqual(expectedException.GetType().FullName, match.Groups["type"].Value, "StreamLogger.Log did not write the correct Exception Type");
// Assert.AreEqual(expectedException.Message, match.Groups["message"].Value, "StreamLogger.Log did not write the correct Exception Message");
}
}
示例9: RecordedMessage
public bool RecordedMessage(LoggerLevel level, string message)
{
return messages.Contains(level.ToString().ToUpper() + ": " + message);
}
示例10: RegisterLoggers
private static void RegisterLoggers(LoggerLevel loggerLevel)
{
Container.Register(
Component.For(typeof(ILogger))
.ImplementedBy(typeof(ConsoleLogger))
.Parameters(Parameter.ForKey("loglevel").Eq(loggerLevel.ToString()))
.LifeStyle.Is(LifestyleType.Singleton));
}
示例11: Log
protected override void Log(LoggerLevel loggerLevel, string loggerName, string message, Exception exception)
{
if (eventLog == null) return; // just in case it was disposed
EventLogEntryType type = TranslateLevel(loggerLevel);
String contentToLog;
if (exception == null)
{
contentToLog = string.Format(CultureInfo.CurrentCulture, "[{0}] '{1}' message: {2}", loggerLevel.ToString(), loggerName, message);
}
else
{
contentToLog = string.Format(CultureInfo.CurrentCulture, "[{0}] '{1}' message: {2} exception: {3} {4} {5}",
loggerLevel.ToString(), loggerName, message, exception.GetType(), exception.Message,
exception.StackTrace);
}
eventLog.WriteEntry(contentToLog, type);
}
示例12: Log
protected override void Log(LoggerLevel loggerLevel, String loggerName, String message, Exception exception)
{
if (writer == null) return; // just in case it's been disposed
writer.WriteLine("[{0}] '{1}' {2}", loggerLevel.ToString(), loggerName, message);
if (exception != null)
{
writer.WriteLine("[{0}] '{1}' {2}: {3} {4}",
loggerLevel.ToString(),
loggerName,
exception.GetType().FullName,
exception.Message,
exception.StackTrace);
}
}
示例13: Log
protected void Log(LoggerLevel loggerLevel, string loggerName, string message, Exception exception)
{
TextWriter output = Console.Out;
if (loggerLevel == LoggerLevel.Error || loggerLevel == LoggerLevel.Fatal)
output = Console.Error;
output.WriteLine("[{0}] '{1}' {2}", loggerLevel, loggerName, message);
if (exception != null)
{
output.WriteLine("[{0}] '{1}' {2}: {3} {4}", new object[] { loggerLevel.ToString(), loggerName, exception.GetType().FullName, exception.Message, exception.StackTrace });
}
}
示例14: Log
public void Log(string strLogMessage, LoggerLevel level)
{
lock (this) {
string strType = System.Configuration.ConfigurationManager.AppSettings["logType"];
switch (strType) {
case "eventlog":
EventLogEntryType et;
switch (level) {
case LoggerLevel.Error:
et = EventLogEntryType.Error;
break;
case LoggerLevel.Information:
et = EventLogEntryType.Information;
break;
case LoggerLevel.Warning:
et = EventLogEntryType.Warning;
break;
default:
et = EventLogEntryType.Information;
break;
}
StampEventLogEntry(strLogMessage, et);
break;
case "xml":
StampXmlLogEntry(strLogMessage, level);
break;
default:
string strFile = "";
try {
strFile = System.Configuration.ConfigurationManager.AppSettings["logFile"];
} catch (System.Configuration.SettingsPropertyNotFoundException) {
strFile = System.Environment.CurrentDirectory + "\\debug.log";
}
if (strFile == "") {
strFile = System.Environment.CurrentDirectory + "\\debug.log";
} else {
strFile = System.Environment.CurrentDirectory + "\\" + strFile;
}
StreamWriter objLogFile = File.AppendText(strFile);
objLogFile.WriteLine(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss.ffffff") + "|" + level.ToString() + "|" + strLogMessage);
objLogFile.Close();
break;
}
}
}
示例15: Warn
public void Warn(string message, Exception exception)
{
Log(LoggerLevel.Warn, message, exception);
}
/// <summary>
/// Logs an warn message.
/// </summary>
/// <param name="format">Message format</param>
/// <param name="args">Array of objects to write using format</param>
public void Warn( string format, params Object[] args )