本文整理汇总了C#中ILogMessage类的典型用法代码示例。如果您正苦于以下问题:C# ILogMessage类的具体用法?C# ILogMessage怎么用?C# ILogMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILogMessage类属于命名空间,在下文中一共展示了ILogMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: From
public static AssetLogMessage From(Package package, IReference assetReference, ILogMessage logMessage, string assetPath, int line = 0, int character = 0)
{
// Transform to AssetLogMessage
var assetLogMessage = logMessage as AssetLogMessage;
if (assetLogMessage == null)
{
assetLogMessage = new AssetLogMessage(null, assetReference, logMessage.Type, AssetMessageCode.CompilationMessage, assetReference?.Location, logMessage.Text)
{
Exception = (logMessage as LogMessage)?.Exception
};
}
// Set file (and location if available)
assetLogMessage.File = assetPath;
assetLogMessage.Line = line;
assetLogMessage.Character = character;
// Generate location (if it's a Yaml exception)
var yamlException = (logMessage as LogMessage)?.Exception as YamlException;
if (yamlException != null)
{
assetLogMessage.Line = yamlException.Start.Line;
assetLogMessage.Character = yamlException.Start.Column;
// We've already got everything, no need to pollute log with stack trace of exception
assetLogMessage.Exception = null;
}
return assetLogMessage;
}
示例2: OnLog
protected override void OnLog(ILogMessage logMessage)
{
// Always log when debugger is attached
if (logMessage.Type < LogLevel)
{
return;
}
var color = ConsoleColor.Gray;
// set the color depending on the message log level
switch (logMessage.Type)
{
case LogMessageType.Debug:
color = ConsoleColor.DarkGray;
break;
case LogMessageType.Verbose:
color = ConsoleColor.Gray;
break;
case LogMessageType.Info:
color = ConsoleColor.Green;
break;
case LogMessageType.Warning:
color = ConsoleColor.Yellow;
break;
case LogMessageType.Error:
case LogMessageType.Fatal:
color = ConsoleColor.Red;
break;
}
logger(GetDefaultText(logMessage), color);
}
示例3: OnLog
/// <inheriteddoc />
protected override void OnLog(ILogMessage msg, ref bool success)
{
var sb = new StringBuilder();
CreateString(msg, sb);
Debug.WriteLine(sb.ToString());
}
示例4: ExportLogMessage
protected override void ExportLogMessage(IRepositoryContext context, ISession session, ILogMessage message)
{
WriteLine();
if (message.Severity == LogMessageSeverity.Verbose)
Write("{0} {1}\r\n", message.Timestamp, message.Caption.Trim());
else
{
var severity = message.Severity.ToString();
if (severity.StartsWith("Info") || severity.StartsWith("Warn"))
severity = severity.Substring(0, 4);
else
severity = severity.ToUpperInvariant();
Write("{0} {2} {1}\r\n", message.Timestamp, message.Caption.Trim(), severity);
}
if (string.IsNullOrEmpty(message.Description) == false)
{
Write("{0}\r\n", message.Description.Trim());
}
Write("Category: {0} from {1}", message.CategoryName, message.LogSystem);
if (string.IsNullOrEmpty(message.ClassName) == false)
{
Write(" {0}.{1}", message.ClassName, message.MethodName);
}
if (string.IsNullOrEmpty(message.FileName) == false)
{
Write(" in {0} ({1})", message.FileName, message.LineNumber);
}
WriteLine();
Write("Thread: {0} ({1}) for {2}\r\n", message.ThreadName, message.ThreadId, message.UserName);
IExceptionInfo currentException = message.Exception;
if (currentException != null)
{
if (Config.IncludeExceptionDetails)
{
var label = "EXCEPTION";
while (currentException != null)
{
Write("{0}: {1} - {2} from {3}\r\nStack Trace:\r\n{4}\r\n",
label, currentException.TypeName, currentException.Message.Trim(),
currentException.Source, currentException.StackTrace);
currentException = currentException.InnerException;
label = "INNER EXCEPTION";
}
}
else
{
while (currentException != null)
{
Write("{0}: {1}\r\n", currentException.TypeName, currentException.Message.Trim());
currentException = currentException.InnerException;
}
}
WriteLine();
}
}
示例5: LogRaw
protected override void LogRaw(ILogMessage logMessage)
{
buildStep.Logger.Log(logMessage);
mainLogger?.Log(logMessage);
StepLogger?.Log(logMessage);
}
示例6: OnLog
protected override void OnLog(ILogMessage message)
{
var serializableMessage = message as SerializableLogMessage;
if (serializableMessage == null)
{
var assetMessage = message as AssetLogMessage;
if (assetMessage != null)
{
assetMessage.Module = mainLogger.Module;
serializableMessage = new AssetSerializableLogMessage(assetMessage);
}
else
{
var logMessage = message as LogMessage;
serializableMessage = logMessage != null ? new SerializableLogMessage(logMessage) : null;
}
}
if (serializableMessage == null)
{
throw new ArgumentException(@"Unable to process the given log message.", "message");
}
foreach (var remoteLog in remoteLogs)
{
try
{
remoteLog.ForwardSerializableLog(serializableMessage);
}
// ReSharper disable EmptyGeneralCatchClause
catch { }
// ReSharper restore EmptyGeneralCatchClause
}
}
示例7: Log
private void Log(ILogMessage obj)
{
if (MessageLogged != null)
{
MessageLogged(obj);
}
}
示例8: CLogMessage
public CLogMessage(
IMessageSerializer messageSerializer,
DateTime timeStamp,
LogMessageCategoryEnum messageCategory,
bool isException,
bool isRootMessage,
string source,
string message,
string messageStackTrace,
string exceptionStackTrace,
ILogMessage childMessage
)
{
if (messageSerializer == null)
{
throw new ArgumentNullException("messageSerializer");
}
//childMessage allowed to be null
_messageSerializer = messageSerializer;
_timeStamp = timeStamp;
_messageCategory = messageCategory;
_isException = isException;
_isRootMessage = isRootMessage;
_source = source;
_message = message.CrLnNormalize();
_messageStackTrace = messageStackTrace.CrLnNormalize();
_exceptionStackTrace = exceptionStackTrace.CrLnNormalize();
_childMessage = childMessage;
}
示例9: OnMessageLogged
private void OnMessageLogged(ILogMessage msg)
{
if (this.MessageLogged != null)
{
this.MessageLogged(msg);
}
}
示例10: OnLog
/// <inheriteddoc />
protected sealed override void OnLog(ILogMessage msg, ref bool success)
{
lock (SyncRoot)
{
base.OnLog(msg, ref success);
}
}
示例11: Add
public void Add(ILogMessage item)
{
lock(syncObj) //We can just lock because we don't lock anymore while taking. Deadlocks used to occur before, and the fix didn't work 100%, so we now don't lock on Take().
//We were able to do it lockless because we caught dipose and cancel exceptions and continued on them. There is little to no contention on syncObj anymore.
{
messageCollection.Add(item);
}
}
示例12: LogRaw
protected override void LogRaw(ILogMessage logMessage)
{
TimeSpan timestamp = DateTime.Now - startTime;
lock (Messages)
{
Messages.Add(new Message(timestamp.Ticks, logMessage));
}
}
示例13: OnLog
protected override void OnLog(ILogMessage logMessage)
{
Debug.WriteLine(GetDefaultText(logMessage));
var exceptionMsg = GetExceptionText(logMessage);
if (!string.IsNullOrEmpty(exceptionMsg))
{
Debug.WriteLine(exceptionMsg);
}
}
示例14: OnLog
protected override void OnLog(ILogMessage message)
{
if (!activeRemoteLogs)
return;
var serializableMessage = message as SerializableLogMessage;
if (serializableMessage == null)
{
var assetMessage = message as AssetLogMessage;
if (assetMessage != null)
{
assetMessage.Module = mainLogger.Module;
serializableMessage = new AssetSerializableLogMessage(assetMessage);
}
else
{
var logMessage = message as LogMessage;
serializableMessage = logMessage != null ? new SerializableLogMessage(logMessage) : null;
}
}
if (serializableMessage == null)
{
throw new ArgumentException(@"Unable to process the given log message.", "message");
}
for (int i = 0; i < remoteLogs.Count; i++)
{
var remoteLog = remoteLogs[i];
try
{
remoteLog?.ForwardSerializableLog(serializableMessage);
}
// ReSharper disable EmptyGeneralCatchClause
catch
{
// Communication failed, let's null it out so that we don't try again
remoteLogs[i] = null;
TryCloseChannel(remoteLog);
// Check if we still need to log anything
var newActiveRemoteLogs = false;
for (int j = 0; j < remoteLogs.Count; j++)
{
if (remoteLogs[j] != null)
{
newActiveRemoteLogs = true;
break;
}
}
activeRemoteLogs = newActiveRemoteLogs;
}
// ReSharper restore EmptyGeneralCatchClause
}
}
示例15: SendMessage
}// end constructeur
/// <summary>
/// Enregistre Le message dans un fichier de Log
/// </summary>
/// <param name="MonLevel">Niveau de criticité</param>
/// <param name="MonMessage">Message à enresgitrer</param>
/// <param name="MonContexte">Contexte d'exécution</param>
public override void SendMessage(LogLevel MonLevel, ILogMessage MonMessage, ILogContexte MonContexte)
{
DBCnx curCon = DbCnxManager.CreateConnectionFromConnectingString(ConnectionString);
curCon.SQL_Execute("PR_LOG_MESSAGE", "@LOG_LEVEL", MonLevel, "@Origin", MonContexte.Origin, "@scope", MonContexte.Scope, "@loguser", MonContexte.CurrentUser
, "@domaine", MonMessage.Domaine, "@MESSAGE_NUMBER", MonMessage.NumMessage, "@LOG_MESSAGE", MonMessage.TexteMessage, "@OTHERSINFOS", JsonConvert.SerializeObject(MonContexte.InfosComplementaires));
curCon.Dispose();
}