本文整理汇总了C#中LogMessage类的典型用法代码示例。如果您正苦于以下问题:C# LogMessage类的具体用法?C# LogMessage怎么用?C# LogMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogMessage类属于命名空间,在下文中一共展示了LogMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Log
public static void Log(string input)
{
var endpoint = GlobalHost.ConnectionManager.GetConnectionContext<ExecuteEndPoint>().Connection;
var logMessage = new LogMessage(input);
endpoint.Broadcast(logMessage);
}
示例2: LogBlockEnd
public void LogBlockEnd(FunctionId functionId, LogMessage logMessage, int blockId, int delta, CancellationToken cancellationToken)
{
var kvLogMessage = logMessage as KeyValueLogMessage;
if (kvLogMessage == null)
{
return;
}
try
{
// guard us from exception thrown by telemetry
var telemetryEvent = CreateTelemetryEvent(functionId, End);
SetBlockId(telemetryEvent, functionId, blockId);
var durationName = functionId.GetPropertyName(Duration);
telemetryEvent.SetIntProperty(durationName, delta);
var cancellationName = functionId.GetPropertyName(CancellationRequested);
telemetryEvent.SetBoolProperty(cancellationName, cancellationToken.IsCancellationRequested);
_session.PostEvent(telemetryEvent);
}
catch
{
}
}
示例3: RegisterDiagnostics
private static void RegisterDiagnostics(ContainerBuilder builder)
{
builder.Register(
c =>
{
var loggers = c.Resolve<IEnumerable<ILogger>>();
Action<LevelToLog, string> action = (p, s) =>
{
var msg = new LogMessage(p, s);
foreach (var logger in loggers)
{
try
{
logger.Log(msg);
}
catch (NLogRuntimeException)
{
// Ignore it and move on to the next logger.
}
}
};
return new SystemDiagnostics(action, null);
})
.As<SystemDiagnostics>()
.SingleInstance();
}
示例4: ProcessMessage
/// <summary>
/// Processes the specified log message
/// </summary>
/// <param name="message"></param>
protected override void ProcessMessage(LogMessage message)
{
// Call base
base.ProcessMessage(message);
// Transform log type and strip the tag
Imports.OxideNative_LogType logType;
string msg;
switch (message.Type)
{
case LogType.Debug:
logType = Imports.OxideNative_LogType.Debug;
msg = message.Message.Replace(" [Debug]", ":");
break;
case LogType.Info:
logType = Imports.OxideNative_LogType.Info;
msg = message.Message.Replace(" [Info]", ":");
break;
case LogType.Warning:
logType = Imports.OxideNative_LogType.Warning;
msg = message.Message.Replace(" [Warning]", ":");
break;
case LogType.Error:
logType = Imports.OxideNative_LogType.Error;
msg = message.Message.Replace(" [Error]", ":");
break;
default:
return;
}
// Forward it to native
Imports.OxideNative_WriteLog(logType, msg);
}
示例5: ErrLog
public ErrLog(string msg, string location, string state, LogMessage originalMessage)
{
ErrorMessage = msg;
ParserState = state;
ErrorLocation = location;
LogData = originalMessage;
}
示例6: GetFormatted
/// <summary>
/// Возвращет форматированный текст из представления сообщения <see cref="LogMessage"/>
/// </summary>
/// <param name="message">Представление сообщения <see cref="LogMessage"/></param>
/// <returns>Форматированная строка сообщения</returns>
protected virtual string GetFormatted(LogMessage message) {
string text;
if (!string.IsNullOrEmpty(CustomFormat)) {
text = Regex.Replace(CustomFormat, @"\$\{(\w+)\}", m =>
{
var propName = m.Groups[1].Value;
var prop = message.GetType().GetProperty(propName);
if (null != prop) {
var val = prop.GetValue(message, null);
if (null == val) {
return "";
}
if (val is DateTime) {
return ((DateTime) val).ToString("yyyy-MM-dd HH:mm:ss");
}
return val.ToString();
}
return "";
});
}
else {
text = message.ToString();
}
return text;
}
示例7: LogFailSafe
/// <summary>
/// Fail safe UserLog gate to write internal exception without main logging context, but with max guarantee of regestering
/// synchronous
/// </summary>
public void LogFailSafe(LogMessage message) {
if (null == message) {
return;
}
if (string.IsNullOrEmpty(message.Name)) {
message.Name = "FAILSAFE";
}
try {
StreamWriter wr = null;
for (var i = 0; i < 100; i++) {
try {
wr = new StreamWriter(Path.Combine(EnvironmentInfo.RootDirectory, "failsafelog" + i + ".txt"), true, Encoding.UTF8);
break;
}
// ReSharper disable EmptyGeneralCatchClause
catch (Exception) {}
// ReSharper restore EmptyGeneralCatchClause
}
if (null == wr) {
var tmpfile = Path.GetTempFileName() + ".failsafelog." +
DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss", CultureInfo.InvariantCulture) + ".txt";
wr = new StreamWriter(tmpfile, true, Encoding.UTF8);
}
using (wr) {
wr.WriteLine(message.ToString());
wr.Flush();
}
}
catch (Exception ex) {
throw new LogException("even safe mode fails to be executed", ex);
}
}
示例8: Log
public void Log(LogMessage message)
{
lock (_lock)
{
_wrappedLog.Log(message);
}
}
示例9: Write
/// <summary>
/// Writes a message to this logger
/// </summary>
/// <param name="msg"></param>
internal virtual void Write(LogMessage msg)
{
// If we're set to process immediately, do so, otherwise enqueue
if (processmessagesimmediately)
ProcessMessage(msg);
else
messagequeue.Enqueue(msg);
}
示例10: CreateLogMessage
/// <summary>
/// Creates a log message from the specified arguments
/// </summary>
/// <param name="type"></param>
/// <param name="format"></param>
/// <param name="args"></param>
/// <returns></returns>
protected LogMessage CreateLogMessage(LogType type, string format, object[] args)
{
LogMessage msg = new LogMessage { Type = type, Message =
$"{DateTime.Now.ToShortTimeString()} [{type}] {format}"
};
if (args.Length != 0) msg.Message = string.Format(msg.Message, args);
return msg;
}
示例11: Log
public override void Log ( LogMessage message )
{
Colorize( message.MessageType );
GetWriter( message.MessageType ).WriteLine("{2}", message.DateTime, message.ThreadId, message.MessageText );
Console.ResetColor();
}
示例12: saveLog
public void saveLog(LogLevel logLevel, string message)
{
LogMessage n = new LogMessage (logLevel, message);
if (_messages.Count >= max) {
_messages.RemoveAt (0);
}
_messages.Add (n);
}
示例13: Log
/// <summary>
/// Record the log message to the console.
/// </summary>
/// <param name="logMessage">The log message object to record</param>
protected internal override void Log(LogMessage logMessage)
{
if (logMessage == null) return;
DateTime time = DateTime.FromBinary(logMessage.Time);
String level = Enum.GetName(typeof(LogLevel), logMessage.Level);
Console.WriteLine(OutputFormat, time, level, logMessage.Tag, logMessage.Message);
}
示例14: Display
public static void Display(LogMessage message)
{
writeTimePrefix();
writeTypePrefix(message.LogType, message.BGColor, message.FGColor);
for (int i = 0; i < 40 - message.Message.Length; i++)
message.Message += " ";
Console.WriteLine(message.Message);
}
示例15: Write
/// <summary>
///
/// </summary>
/// <param name="logmessage"></param>
public override void Write(LogMessage logmessage)
{
base.Write(logmessage);
if (logmessage.Level >= this.Level){
Messages.Add(logmessage);
}
}