本文整理汇总了C#中MessageLevel.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MessageLevel.ToString方法的具体用法?C# MessageLevel.ToString怎么用?C# MessageLevel.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageLevel
的用法示例。
在下文中一共展示了MessageLevel.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Post
public IObservable<bool> Post(string url, string message, MessageLevel level = MessageLevel.Info)
{
// Create an HttpClient and send content payload
using (var httpClient = HttpClient)
{
#if __IOS__ || __ANDROID__ || NET45
var content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"message", message},
{"level", level.ToString().ToLower()}
});
#endif
#if NETFX_CORE
var content = new HttpFormUrlEncodedContent(new Dictionary<string, string>
{
{"message", message},
{"level", level.ToString().ToLower()}
});
#endif
#if __IOS__ || __ANDROID__ || NET45
return httpClient.PostAsync(new Uri(url), content)
.ToObservable()
.Select(response => response.IsSuccessStatusCode);
#endif
#if NETFX_CORE
return httpClient.PostAsync(new Uri(url), content)
.AsTask()
.ToObservable()
.Select(response => response.IsSuccessStatusCode);
#endif
}
}
示例2: LastChanceLog
/// <summary>
/// Last chance logging if primary logging sink fails. Usually used on application boot strapping. Log file will be located in
/// either the file location of Log.LastChangeLogFile or in the default folder of the running application. NOTE: Bypasses
/// any configured log provider (log4Net, NLog, TraceLog, etc) and writes directly to text file. Use with extreme care and is
/// not configured for high performance.
/// </summary>
/// <param name="logLevel">Level this message will be logged at</param>
/// <param name="message">Text of message</param>
/// <param name="args">Arguments to supply to message text (if any)</param>
public static void LastChanceLog(MessageLevel logLevel, string message, params object[] args)
{
string logMessage = "";
try
{
_lastChanceLock.EnterWriteLock();
if (CoreConfig.Log.IsLastChanceLogEnabled == false) return; // last chance logging not enabled
logMessage = TextUtils.StringFormat("{0:yyyy-MM-dd HH:mm:ss.fff} {1} {2}", DateTime.Now, logLevel.ToString().ToUpper(), TextUtils.StringFormat(message, args));
File.AppendAllText(CoreConfig.Log.LastChanceLogFile, logMessage + Environment.NewLine);
}
catch (Exception ex)
{
try // write to event log if unable to log to last chance file. This is really the last chance of the last chance!
{
EventLog.WriteEntry("Application Error", string.Format(logMessage, args), EventLogEntryType.Error);
EventLog.WriteEntry("Application Error", string.Format(ex.ToString()), EventLogEntryType.Error);
}
catch (Exception ex2) //couldn't write log to last chance log file or event viewer so swallow exception
{
System.Diagnostics.Debug.WriteLine(string.Format("Error in LastChanceLog: {0}{1}{2}", ex2.Message, Environment.NewLine, logMessage));
}
}
finally
{
_lastChanceLock.ExitWriteLock();
}
}
示例3: PostAsync
public async Task<bool> PostAsync(string url, string message, MessageLevel level = MessageLevel.Info)
{
// Create an HttpClient and send content payload
using (var httpClient = HttpClient)
{
#if __IOS__ || __ANDROID__ || NET45
var content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"message", message},
{"level", level.ToString().ToLower()}
});
#endif
#if NETFX_CORE
var content = new HttpFormUrlEncodedContent(new Dictionary<string, string>
{
{"message", message},
{"level", level.ToString().ToLower()}
});
#endif
var response = await httpClient.PostAsync(new Uri(url), content);
return response.IsSuccessStatusCode;
}
}
示例4: Log
public static void Log(MessageLevel level, string fmt, params object[] args)
{
if (level <= maxLevel) {
string levelString = '[' + level.ToString().Substring(0, 3) + ']';
string msg = string.Format(levelString + fmt, args);
if (UseConsole) {
Console.WriteLine(msg);
}
if (UseFile) {
Writer.WriteLine(msg);
}
System.Diagnostics.Debug.WriteLine(msg);
}
if (UseConsole) {
Console.ResetColor();
}
}
示例5: GenerateOutputMessage
private static void GenerateOutputMessage(string logtext, MessageLevel prefix, string source)
{
switch (LoggingLevel >= prefix)
{
case true:
var _sb = new StringBuilder();
var logtimestamp = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss:sss.fff", CultureInfo.InvariantCulture);
_sb.Append(logtimestamp.PadRight(30));
_sb.Append(prefix.ToString().PadRight(30));
_sb.Append(source.PadRight(40));
_sb.Append(GetCurrentMethod(GetCaller()).PadRight(30));
_sb.Append(logtext);
lock (_syncObject)
{
using (StreamWriter sw = new StreamWriter(LogLocation, true)) { sw.WriteLine(_sb.ToString()); }
}
break;
case false:
break;
}
}
示例6: SetMessage
protected void SetMessage(string message, MessageLevel level = MessageLevel.Info)
{
message = Convert.ToBase64String(Encoding.UTF8.GetBytes(message));
HttpContext.Items[Keys.HttpContextItems.HAS_UI_MESSAGE] = true;
Response.Cookies.Set(new HttpCookie(Keys.Cookies.UI_MESSAGE, string.Format("{0}/{1}", level.ToString().ToLowerInvariant(), message)));
}
示例7: AddPrefix
private static string AddPrefix(string Message, MessageLevel Level)
{
return DateTime.Now + " (" + Level.ToString() + ") " + Message;
}