本文整理汇总了C#中Severity.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Severity.ToString方法的具体用法?C# Severity.ToString怎么用?C# Severity.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Severity
的用法示例。
在下文中一共展示了Severity.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteOutput
//public JobLogger(IConfig config, int skipFrames)
//{
// _pageName = config.SessionContext.PageName;
// _aspSessionId = config.SessionContext.AspSessionId;
// _sessionId = config.SessionContext.SessionId;
// _clientIp = config.SessionContext.ClientIp;
// _syslog = GetLogger(config, skipFrames);
//}
protected override void WriteOutput(string message, Severity severity, LogTo logTo)
{
if (logTo.HasFlag(LogTo.File))
{
_fileHandler.WriteMessage(message, severity.ToString());
}
if (logTo.HasFlag(LogTo.DataBase))
{
_logDataAccess.InsertMessage(message, (int) severity);
}
if (logTo.HasFlag(LogTo.Console))
{
//TODO:implements console
switch(severity)
{
case Severity.Message:
Console.ForegroundColor = ConsoleColor.White;
break;
case Severity.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case Severity.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;
default:
Console.ForegroundColor = ConsoleColor.White;
break;
}
Console.WriteLine("{0} {1}", DateTime.Now.ToShortDateString(), message);
}
}
示例2: PickColor
protected virtual ConsoleColor PickColor(Severity level, out string levelText)
{
bool isDetail = ((int)level & 1) != 0;
bool implicitLevel = level < PrintSeverityAt || isDetail;
ConsoleColor color;
if (level >= Severity.CriticalDetail)
color = isDetail ? ConsoleColor.DarkMagenta : ConsoleColor.Magenta;
else if (level >= Severity.ErrorDetail)
color = isDetail ? ConsoleColor.DarkRed : ConsoleColor.Red;
else if (level >= Severity.WarningDetail)
color = isDetail ? ConsoleColor.DarkYellow : ConsoleColor.Yellow;
else if (level >= Severity.NoteDetail)
color = isDetail ? ConsoleColor.Gray : ConsoleColor.White;
else if (level >= Severity.DebugDetail)
color = isDetail ? ConsoleColor.DarkCyan : ConsoleColor.Cyan;
else if (level >= Severity.VerboseDetail)
color = isDetail ? ConsoleColor.DarkCyan : ConsoleColor.DarkCyan;
else
color = Console.ForegroundColor;
levelText = implicitLevel ? null : level.ToString().Localized();
_lastColor = color;
return color;
}
示例3: Log
/// <summary>
/// Log a message. The current logging level is used to determine
/// if the message is appended to the configured appender
/// or if it is ignored.
/// </summary>
/// <param name="category">The category to which this log statement belongs.</param>
/// <param name="s">The severity of the logging message.</param>
/// <param name="errorMsg">A concise description of the problem encountered.</param>
/// <param name="args">Variable values that are to be captured with the logging statement.</param>
public static void Log(Severity s, string errorMsg, params object[] args)
{
if (args != null && args.Length > 0)
LogMessage(s, Format(s.ToString() + ": " + errorMsg, args), null);
else
LogMessage(s, errorMsg, null);
}
示例4: ExceptionLog
public ExceptionLog(Exception exception, string source, string method, Severity severity, string title = "")
: this()
{
Type = exception.GetType().Name;
StackTrace = exception.StackTrace;
Source = string.IsNullOrEmpty(source) ? exception.Source : source;
Severity = severity.ToString();
Message = exception.Message;
InnerException = exception.InnerException != null ? exception.InnerException.ToString() : string.Empty;
AdditionalInfo = FormatExceptionData(exception.Data);
TargetSite = exception.TargetSite == null ? "" : exception.TargetSite.Name;
Title = string.IsNullOrEmpty(title) ? method : title;
}
示例5: logdata
public void logdata(string logfile, string data, bool logtodb, Severity severity)
{
if (logtofile)
{
System.IO.File.AppendAllText(logfile, Environment.NewLine + "------------------------------------------------------------------------------------------------");
System.IO.File.AppendAllText(logfile, string.Format("{0}Timestamp: {1}", Environment.NewLine, DateTime.Now));
System.IO.File.AppendAllText(logfile, string.Format("{0}Message: {1}", Environment.NewLine, data));
System.IO.File.AppendAllText(logfile, string.Format("{0}Severity: {1}", Environment.NewLine, severity.ToString()));
System.IO.File.AppendAllText(logfile, Environment.NewLine + "------------------------------------------------------------------------------------------------");
}
if (logtodb)
{
//insertIntoJobEventLog(data, job, severity);
}
}
示例6: Log
public override bool Log(string Message, Severity severity = Severity.Info)
{
try
{
string LogFileName = Directory.GetCurrentDirectory() + "LogFile.txt";
File.AppendAllText(LogFileName, string.Format("Priority({0}) > {1}{2}", severity.ToString(), Message, Environment.NewLine));
/*
OR
StreamWriter SW = null;
try
{
if (!File.Exists(LogFileName))
SW = File.CreateText(LogFileName);
else
SW = File.AppendText(LogFileName);
SW.WriteLine(string.Format("Priority({0}) > {1}", PriorityToText(severity), Message));
SW.Close();
}
finally
{
if (SW != null)
SW.Dispose();
}
*/
return true;
}
catch
{
return false;
throw new NotImplementedException();
}
}
示例7: LogEngineHealthEvent
/// <summary>
/// Logs engine health event
/// </summary>
internal void LogEngineHealthEvent(Exception exception,
Severity severity,
int id,
Dictionary<String, String> additionalInfo)
{
Dbg.Assert(exception != null, "Caller should validate the parameter");
LogContext logContext = new LogContext();
logContext.EngineVersion = Version.ToString();
logContext.HostId = Host.InstanceId.ToString();
logContext.HostName = Host.Name;
logContext.HostVersion = Host.Version.ToString();
logContext.RunspaceId = InstanceId.ToString();
logContext.Severity = severity.ToString();
if (this.RunspaceConfiguration == null)
{
logContext.ShellId = Utils.DefaultPowerShellShellID;
}
else
{
logContext.ShellId = this.RunspaceConfiguration.ShellId;
}
MshLog.LogEngineHealthEvent(
logContext,
id,
exception,
additionalInfo);
}
示例8: Write
protected virtual void Write(int msg, [NotNull] string text, Severity severity, [NotNull] string fileName, TextSpan textSpan, [NotNull] string details)
{
if (IgnoredMessages.Contains(msg))
{
return;
}
if (!string.IsNullOrEmpty(details))
{
text += ": " + details;
}
var fileInfo = !string.IsNullOrEmpty(fileName) ? fileName : "scc.cmd";
var projectDirectory = Configuration.Get(Constants.Configuration.ProjectDirectory);
if (!string.IsNullOrEmpty(projectDirectory))
{
if (fileInfo.StartsWith(projectDirectory, StringComparison.OrdinalIgnoreCase))
{
fileInfo = fileInfo.Mid(projectDirectory.Length + 1);
}
}
var lineInfo = textSpan.Length == 0 ? $"({textSpan.LineNumber},{textSpan.LinePosition})" : $"({textSpan.LineNumber},{textSpan.LinePosition},{textSpan.LineNumber},{textSpan.LinePosition + textSpan.Length})";
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write($"{fileInfo}{lineInfo}: ");
switch (severity)
{
case Severity.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case Severity.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;
default:
Console.ForegroundColor = ConsoleColor.DarkGray;
break;
}
Console.Write(severity.ToString().ToLowerInvariant());
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(" SCC{0}: ", msg.ToString("0000"));
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(text);
}
示例9: ErrorReported
public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity)
{
Errors.AppendLine(string.Format("{0}:{1} - {2} at Line {3}", new object[] { severity.ToString(), errorCode.ToString(), message, span.Start.Line.ToString() }));
}
示例10: WriteCore
public void WriteCore(Severity type, object context, string text)
{
string loc = MessageSink.ContextToString(context);
if (!string.IsNullOrEmpty(loc))
text = loc + ": " + text;
Trace.WriteLine(text, type.ToString());
}
示例11: GetLogContext
/// <summary>
/// Generate LogContext structure based on executionContext and invocationInfo passed in.
///
/// LogContext structure is used in log provider interface.
/// </summary>
/// <param name="executionContext"></param>
/// <param name="invocationInfo"></param>
/// <param name="severity"></param>
/// <returns></returns>
private static LogContext GetLogContext(ExecutionContext executionContext, InvocationInfo invocationInfo, Severity severity)
{
if (executionContext == null)
return null;
LogContext logContext = new LogContext();
string shellId = executionContext.ShellID;
logContext.ExecutionContext = executionContext;
logContext.ShellId = shellId;
logContext.Severity = severity.ToString();
if (executionContext.EngineHostInterface != null)
{
logContext.HostName = executionContext.EngineHostInterface.Name;
logContext.HostVersion = executionContext.EngineHostInterface.Version.ToString();
logContext.HostId = (string)executionContext.EngineHostInterface.InstanceId.ToString();
}
logContext.HostApplication = String.Join(" ", Environment.GetCommandLineArgs());
if (executionContext.CurrentRunspace != null)
{
logContext.EngineVersion = executionContext.CurrentRunspace.Version.ToString();
logContext.RunspaceId = executionContext.CurrentRunspace.InstanceId.ToString();
Pipeline currentPipeline = ((RunspaceBase)executionContext.CurrentRunspace).GetCurrentlyRunningPipeline();
if (currentPipeline != null)
{
logContext.PipelineId = currentPipeline.InstanceId.ToString(CultureInfo.CurrentCulture);
}
}
logContext.SequenceNumber = NextSequenceNumber;
try
{
if (executionContext.LogContextCache.User == null)
{
logContext.User = Environment.UserDomainName + "\\" + Environment.UserName;
executionContext.LogContextCache.User = logContext.User;
}
else
{
logContext.User = executionContext.LogContextCache.User;
}
}
catch (InvalidOperationException)
{
logContext.User = Logging.UnknownUserName;
}
System.Management.Automation.Remoting.PSSenderInfo psSenderInfo =
executionContext.SessionState.PSVariable.GetValue("PSSenderInfo") as System.Management.Automation.Remoting.PSSenderInfo;
if (psSenderInfo != null)
{
logContext.ConnectedUser = psSenderInfo.UserInfo.Identity.Name;
}
logContext.Time = DateTime.Now.ToString(CultureInfo.CurrentCulture);
if (invocationInfo == null)
return logContext;
logContext.ScriptName = invocationInfo.ScriptName;
logContext.CommandLine = invocationInfo.Line;
if (invocationInfo.MyCommand != null)
{
logContext.CommandName = invocationInfo.MyCommand.Name;
logContext.CommandType = invocationInfo.MyCommand.CommandType.ToString();
switch (invocationInfo.MyCommand.CommandType)
{
case CommandTypes.Application:
logContext.CommandPath = ((ApplicationInfo)invocationInfo.MyCommand).Path;
break;
case CommandTypes.ExternalScript:
logContext.CommandPath = ((ExternalScriptInfo)invocationInfo.MyCommand).Path;
break;
}
}
return logContext;
}
示例12: FormatMessage
public static string FormatMessage(Severity type, object context, string format, params object[] args)
{
string loc = LocationString(context);
string formatted = Localize.From(format, args);
if (string.IsNullOrEmpty(loc))
return Localize.From(type.ToString()) + ": " + formatted;
else
return loc + ": " +
Localize.From(type.ToString()) + ": " + formatted;
}
示例13: Report
public static void Report(Exception ex, Dictionary<string, string> args, Severity type)
{
if (Active) {
if (Logging.DebugOutline) {
#region Debug Output
string key = "";
string value = "";
if (args != null && args.Keys.Count>0){//args?.Keys.Count > 0) {
key = args.Keys.First ();
value = args [key];
}
Debug.WriteLine (string.Format("[{0}] {1}: {2};\n\rStackTrace:\n\r{3}", type.ToString(), key,value,ex != null ? ex.ToString():""));
#endregion
}
}
}
示例14: Source
/// <summary>
/// Sets up the source object
/// </summary>
/// <param name="parent">The parent of the source</param>
/// <param name="severity">Source severity</param>
public Source( Tag parent, Severity severity )
{
m_Severity = severity;
m_Name = severity.ToString( );
m_FullName = ( parent.IsRootTag ? m_Name : parent.FullName + "." + m_Name );
}
示例15: CheckReportForSeverity
/// <summary>
/// Checks if the report has the severity.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="value">The value.</param>
/// <returns><c>true</c> if there is a violation with that severity, <c>false</c> otherwise.</returns>
private static bool CheckReportForSeverity(XmlDocument document, Severity value)
{
var nodes = document.SelectNodes("/CodeItRightReport/Violations/Violation[Severity='" + value.ToString() + "']");
return nodes.Count > 0;
}