Visual Basic (Declaration) | |
---|---|
Public Enum LogLevels Inherits System.Enum |
C# | |
---|---|
public enum LogLevels : System.Enum |
Member | Description |
---|---|
Critical | Logs a Fatal error |
Error | Logs an Error |
Info | Logs an Informational message |
None | Logging is disabled |
Verbose | Logs a Verbose message |
Warning | Logs a Warning |
C# | ![]() |
---|---|
LogOutputs output = Log.Config.Output; try { string messageText = "Warning will robinson, DANGER!"; Log.Config.SetOutputFormat(LogOutputs.All, "{Message}"); Log.Config.SetOutputLevel(LogOutputs.All, LogLevels.Info); LogLevels newLevel = LogLevels.Warning; Assert.AreEqual(LogLevels.Info, Log.Config.SetOutputLevel(LogOutputs.AspNetTrace, newLevel)); Assert.AreEqual(LogLevels.Info, Log.Config.SetOutputLevel(LogOutputs.TraceWrite, newLevel)); Assert.AreEqual(LogLevels.Info, Log.Config.SetOutputLevel(LogOutputs.Console, newLevel)); Assert.AreEqual(LogLevels.Info, Log.Config.SetOutputLevel(LogOutputs.EventLog, newLevel)); Assert.AreEqual(LogLevels.Info, Log.Config.SetOutputLevel(LogOutputs.LogFile, newLevel)); Assert.AreEqual(LogLevels.None, Log.Config.SetOutputLevel(LogOutputs.None, newLevel)); Log.Config.Output = LogOutputs.All & ~LogOutputs.EventLog; TextWriter sw = new StringWriter(), orig = Console.Out; Console.SetOut(sw); string tempFile = Path.GetTempFileName(); string origLog = Log.Config.LogFile; Log.Config.LogFile = tempFile; try { Log.Warning(messageText); Log.Info("Hello"); Log.Verbose("Hello"); } finally { Console.SetOut(orig); Log.Config.LogFile = origLog; } Assert.AreEqual(messageText, _lastTrace.Substring(GetType().FullName.Length + 2)); Assert.AreEqual(messageText, sw.ToString().Trim()); Assert.AreEqual(messageText, File.ReadAllText(tempFile).Trim()); } finally { Log.Config.Output = output; Log.Config.SetOutputLevel(LogOutputs.All, LogLevels.Verbose); Log.Config.SetOutputFormat(LogOutputs.All, "[{ManagedThreadId}] {Level} - {FullMessage}"); } |
VB.NET | ![]() |
---|---|
Dim output As LogOutputs = Log.Config.Output Try Dim messageText As String = "Warning will robinson, DANGER!" Log.Config.SetOutputFormat(LogOutputs.All, "{Message}") Log.Config.SetOutputLevel(LogOutputs.All, LogLevels.Info) Dim newLevel As LogLevels = LogLevels.Warning Assert.AreEqual(LogLevels.Info, Log.Config.SetOutputLevel(LogOutputs.AspNetTrace, newLevel)) Assert.AreEqual(LogLevels.Info, Log.Config.SetOutputLevel(LogOutputs.TraceWrite, newLevel)) Assert.AreEqual(LogLevels.Info, Log.Config.SetOutputLevel(LogOutputs.Console, newLevel)) Assert.AreEqual(LogLevels.Info, Log.Config.SetOutputLevel(LogOutputs.EventLog, newLevel)) Assert.AreEqual(LogLevels.Info, Log.Config.SetOutputLevel(LogOutputs.LogFile, newLevel)) Assert.AreEqual(LogLevels.None, Log.Config.SetOutputLevel(LogOutputs.None, newLevel)) Log.Config.Output = LogOutputs.All And Not LogOutputs.EventLog Dim sw As TextWriter = New StringWriter(), orig As TextWriter = Console.Out Console.SetOut(sw) Dim tempFile As String = Path.GetTempFileName() Dim origLog As String = Log.Config.LogFile Log.Config.LogFile = tempFile Try Log.Warning(messageText) Log.Info("Hello") Log.Verbose("Hello") Finally Console.SetOut(orig) Log.Config.LogFile = origLog End Try Assert.AreEqual(messageText, _lastTrace.Substring([GetType]().FullName.Length + 2)) Assert.AreEqual(messageText, sw.ToString().Trim()) Assert.AreEqual(messageText, File.ReadAllText(tempFile).Trim()) Finally Log.Config.Output = output Log.Config.SetOutputLevel(LogOutputs.All, LogLevels.Verbose) Log.Config.SetOutputFormat(LogOutputs.All, "[{ManagedThreadId}] {Level} - {FullMessage}") End Try |
System.Object
System.ValueType
System.Enum
CSharpTest.Net.Logging.LogLevels
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7