本文整理汇总了C#中TraceLevel.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# TraceLevel.ToString方法的具体用法?C# TraceLevel.ToString怎么用?C# TraceLevel.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TraceLevel
的用法示例。
在下文中一共展示了TraceLevel.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SlidingWindowTraceFilter
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="window">The duration of the sliding window.</param>
/// <param name="threshold">The maximum number of matching trace messages to allow before triggering a notification.</param>
/// <param name="filter">The optional event filter to apply on each <see cref="TraceEvent"/>.</param>
/// <param name="message">The optional message to use for notifications.</param>
/// <param name="level">The maximum trace level of trace messages that will match the filter.</param>
public SlidingWindowTraceFilter(TimeSpan window, int threshold, Func<TraceEvent, bool> filter = null, string message = null, TraceLevel level = TraceLevel.Error)
{
_window = window;
_level = level;
Threshold = threshold;
_filter = filter;
_notificationMessage = message ?? string.Format("{0} events at level '{1}' or lower have occurred within time window {2}.", threshold, level.ToString(), _window);
}
示例2: Trace
/// <summary>
/// Writes the specified trace level, message and optional exception.
/// </summary>
/// <param name="level">The <see cref="TraceLevel"/> at which to write this trace.</param>
/// <param name="message">The trace message.</param>
/// <param name="ex">The trace exception. This parameter is optional.</param>
public void Trace(TraceLevel level, string message, Exception ex)
{
string traceMessage = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff", CultureInfo.InvariantCulture) + " " + level.ToString("g") + " " + message;
if (_traceMessages.Count >= 1000)
_traceMessages.Dequeue();
_traceMessages.Enqueue(traceMessage);
}
示例3: TraceLine
private static void TraceLine(TraceLevel level, string format, object[] args)
{
if ((args == null) || (args.Length == 0))
{
format = format.Replace("{", "{{");
format = format.Replace("}", "}}");
}
string message = /*DateTime.Now.ToString("HH:mm:ss") + " : " +*/ string.Format(format, args);
Trace.WriteLineIf(DoTrace(level), message, level.ToString());
}
示例4: Trace
/// <summary>
/// Writes the specified trace level, message and optional exception.
/// </summary>
/// <param name="level">The <see cref="TraceLevel"/> at which to write this trace.</param>
/// <param name="message">The trace message.</param>
/// <param name="ex">The trace exception. This parameter is optional.</param>
public void Trace(TraceLevel level, string message, Exception ex)
{
if (_traceMessages.Count >= 1000)
_traceMessages.Dequeue();
StringBuilder sb = new StringBuilder();
sb.Append(DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff", CultureInfo.InvariantCulture));
sb.Append(" ");
sb.Append(level.ToString("g"));
sb.Append(" ");
sb.Append(message);
_traceMessages.Enqueue(sb.ToString());
}
示例5: Initialize
public static void Initialize(string logName, TraceLevel level)
{
if (!initialized)
{
Level = level;
if (writer == null && Level > TraceLevel.Off)
{
writer = new InternalTraceWriter(logName);
writer.WriteLine("InternalTrace: Initializing at level " + Level.ToString());
}
initialized = true;
}
}
示例6: Log
public static void Log(TraceLevel level, string message, string category, Exception ex)
{
Writer.WriteLine("{0} {1,-5} [{2,2}] {3}: {4}",
DateTime.Now.ToString(TIME_FMT),
level == TraceLevel.Verbose ? "Debug" : level.ToString(),
#if NET_2_0
System.Threading.Thread.CurrentThread.ManagedThreadId,
#else
AppDomain.GetCurrentThreadId(),
#endif
category,
message);
if (ex != null)
Writer.WriteLine(ex.ToString());
}
示例7: Trace
// Token: 0x060002C0 RID: 704
// RVA: 0x0002F2C8 File Offset: 0x0002D4C8
public void Trace(TraceLevel level, string message, Exception ex)
{
string item = string.Concat(new string[]
{
DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff", CultureInfo.InvariantCulture),
" ",
level.ToString("g"),
" ",
message
});
if (this._traceMessages.Count >= 1000)
{
this._traceMessages.Dequeue();
}
this._traceMessages.Enqueue(item);
}
示例8: Start
public static IisExpressWrapper Start(string appPath, TraceLevel traceLevel = TraceLevel.none)
{
int port =
CassiniDev.CassiniNetworkUtils.GetAvailablePort(
8000,
8999,
System.Net.IPAddress.Loopback,
includeIdlePorts: false);
if (port == 0)
{
throw new ApplicationException("Couldn't get available port for new IISExpress instance.");
}
var startInfo = new System.Diagnostics.ProcessStartInfo()
{
Arguments = String.Format(@"/path:""{0}"" /systray:true /clr:v4.0 /trace:{1} /port:{2}", appPath, traceLevel.ToString(), port),
FileName = @"C:\Program Files (x86)\IIS Express\iisexpress.exe",
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
RedirectStandardError = true,
//RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
};
var process = System.Diagnostics.Process.Start(startInfo);
var iew = new IisExpressWrapper(appPath, port, process);
process.OutputDataReceived += iew.process_OutputDataReceived;
process.ErrorDataReceived += iew.process_ErrorDataReceived;
process.BeginErrorReadLine();
process.BeginOutputReadLine();
// Hack: wait a little for IIS Express to start.
iew._iisStartedEvent.Wait(TimeSpan.FromMilliseconds(2000));
return iew;
}
示例9: writeAudit
public static void writeAudit(string appName, TraceLevel traceLevel, string message, string userID)
{
if (traceType == TraceType.DB || traceType == TraceType.Both)
{
Trace trace = new Trace();
trace.AppName = appName;
trace.Message = message;
trace.TraceType = (short)traceLevel;
trace.TraceLevel = (short)traceLevel;
trace.UserID = userID;
trace.CreateDateTime = DateTime.Now;
DBLogs.Traces.Add(trace);
DBLogs.SaveChanges();
}
if (traceType == TraceType.File || traceType == TraceType.Both)
{
string msg = string.Empty;
msg = DateTime.Now.ToLongDateString() + " : " + appName + " : " + traceLevel.ToString() + " : " +
message + " : " + userID;
writeFile(msg,WS_LogsFilePath + "\\" + traceFileName);
}
}
示例10: Write
/// <summary>
/// Writes a message to the log
/// </summary>
/// <param name="message"></param>
/// <param name="level"></param>
public void Write(string message, TraceLevel level)
{
if (!MayWriteType(level))
return;
var caller = "TShock";
var frame = new StackTrace().GetFrame(2);
if (frame != null)
{
var meth = frame.GetMethod();
if (meth != null && meth.DeclaringType != null)
caller = meth.DeclaringType.Name;
}
var logEntry = string.Format("{0} - {1}: {2}: {3}",
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
caller, level.ToString().ToUpper(), message);
try
{
_logWriter.WriteLine(logEntry);
_logWriter.Flush();
}
catch (ObjectDisposedException)
{
ServerApi.LogWriter.PluginWriteLine(TShock.instance, logEntry, TraceLevel.Error);
Console.WriteLine("Unable to write to log as log has been disposed.");
Console.WriteLine("{0} - {1}: {2}: {3}",
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
caller, level.ToString().ToUpper(), message);
}
}
示例11: Log
// ----------------------------------------------------------------------
private void Log( TraceLevel logLevel, object message, Exception exception )
{
if ( !IsSupportedException( exception ) )
{
return;
}
if ( level.Level >= logLevel )
{
StringBuilder buf = new StringBuilder( name );
buf.Append( ": " );
switch ( logLevel )
{
case TraceLevel.Off:
buf.Append( "Fatal" );
break;
case TraceLevel.Verbose:
buf.Append( "Debug" );
break;
default:
buf.Append( logLevel.ToString() );
break;
}
buf.Append( ": " );
if ( message != null )
{
buf.Append( message );
}
if ( exception != null )
{
buf.Append( ": " );
buf.Append( exception.ToString() );
}
switch ( logLevel )
{
case TraceLevel.Off: // used by 'fatal'
case TraceLevel.Error:
Trace.TraceError( buf.ToString() );
break;
case TraceLevel.Warning:
Trace.TraceWarning( buf.ToString() );
break;
case TraceLevel.Info:
goto default;
case TraceLevel.Verbose:
goto default;
default:
Trace.TraceInformation( buf.ToString() );
break;
}
}
}
示例12: InternalWrite
private static void InternalWrite(TraceLevel level, string format, params object[] args)
{
try
{
if (_init == 0)
{
if (0 == System.Threading.Interlocked.Exchange(ref _init, 1))
{ Open(); }
}
int depth = 2;
if (args.Length > 0)
format = String.Format(format, args);
if (level <= _consoleLogLevel)
Console_LogWrite(level, format);
StackFrame frame;
System.Reflection.MethodBase method;
do
{
frame = new StackFrame(depth++);
method = frame.GetMethod();
}
while (method.ReflectedType.FullName.StartsWith("System.", StringComparison.OrdinalIgnoreCase) ||
method.ReflectedType.GetCustomAttributes(typeof(System.Diagnostics.DebuggerNonUserCodeAttribute), true).Length > 0);
string methodName, callingType;
methodName = String.Format("{0}", method);
callingType = String.Format("{0}", method.ReflectedType);
string full = String.Format("{0:D2}{1,8} - {2} at {3}",
System.Threading.Thread.CurrentThread.ManagedThreadId,
level == TraceLevel.Off ? "None" : level.ToString(),
format, methodName);
Trace.WriteLine(full, callingType);
if (LogWrite != null)
LogWrite(method, level, format);
}
catch (Exception e)
{ Trace.WriteLine(e.ToString(), "CSharpTest.Net.QuickLog.Write()"); }
}
示例13: GetLogLevel
private LogLevel GetLogLevel(TraceLevel level)
{
// translates webapi log level to nlog log level
return LogLevel.FromString(level.ToString());
}
示例14: TurnTraceSwitchOn
public static void TurnTraceSwitchOn(TraceLevel traceLevel = TraceLevel.Info)
{
TraceSwitch = new TraceSwitch("DataConnection", "DataConnection trace switch", traceLevel.ToString());
}
示例15: Log
private static void Log(TraceLevel level, string message)
{
string.Format("{0}:{1}:{2}: {3}",
(object) (level != TraceLevel.Off ? level.ToString().PadRight(7) : "Always".PadRight(7)),
(object) DateTime.UtcNow.ToString("yyyyMMdd.HHmmss"),
(object) ("(" + DateTime.Now.ToString("yyyyMMdd.HHmmss:fffff ") + ")"), (object) message);
}