本文整理汇总了C#中LogEntry.AddErrorMessage方法的典型用法代码示例。如果您正苦于以下问题:C# LogEntry.AddErrorMessage方法的具体用法?C# LogEntry.AddErrorMessage怎么用?C# LogEntry.AddErrorMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogEntry
的用法示例。
在下文中一共展示了LogEntry.AddErrorMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMessageCore
/// <summary>
/// Append the log entry to the configured text file.
/// </summary>
/// <param name="logEntry"><see cref="LogEntry"></see> to be appended to logging file</param>
protected override void SendMessageCore(LogEntry logEntry)
{
try
{
WriteMessageToFile(logEntry);
}
catch (Exception e)
{
logEntry.AddErrorMessage(SR.SinkFailure(e.ToString()));
throw;
}
catch
{
logEntry.AddErrorMessage(SR.SinkFailure(SR.UnknownError));
}
}
示例2: SendMessageCore
/// <summary>
/// Fire a new <see cref="LoggingWMISinkEvent"/> with the properties of the log entry.
/// </summary>
/// <param name="log">Log message to send.</param>
protected override void SendMessageCore(LogEntry log)
{
try
{
LoggingWMISinkEvent.Fire(log);
}
catch (Exception e)
{
log.AddErrorMessage(SR.SinkFailure(e.ToString()));
throw;
}
catch
{
log.AddErrorMessage(SR.SinkFailure(SR.UnknownError));
}
}
示例3: SendMessageCore
/// <summary>
/// Execute a stored procedure to record the log entry.
/// </summary>
/// <param name="logEntry"><see cref="LogEntry"></see> to send to database</param>
protected override void SendMessageCore(LogEntry logEntry)
{
if (ValidateParameters(logEntry))
{
try
{
ExecuteStoredProcedure(logEntry);
}
catch (Exception e)
{
logEntry.AddErrorMessage(SR.SinkFailure(e.ToString()));
throw;
}
catch
{
logEntry.AddErrorMessage(SR.SinkFailure(SR.UnknownError));
}
}
}
示例4: SendMessageCore
/// <summary>
/// Send the log entry to the configured message queue path.
/// </summary>
/// <param name="log">Log message to send.</param>
protected override void SendMessageCore(LogEntry log)
{
if (ValidateQueuePath(log))
{
try
{
SendMessageToQueue(log);
}
catch (Exception e)
{
log.AddErrorMessage(SR.SinkFailure(e.ToString()));
throw;
}
catch
{
log.AddErrorMessage(SR.SinkFailure(SR.UnknownError));
}
}
}
示例5: LogEntryCloneMethodTest
public void LogEntryCloneMethodTest()
{
LogEntry entry = new LogEntry();
entry.ActivityId = new Guid("AAAABBBBCCCCDDDDAAAABBBBCCCCDDDD");
entry.AddErrorMessage("LogEntryCloneMethodTest exception");
entry.Categories.Add("Error");
entry.EventId = 1;
entry.ExtendedProperties.Add("key1", "value1");
entry.Message = "To test the cloning method";
entry.Priority = 10;
entry.Severity = TraceEventType.Critical;
entry.Title = "LogEntryCloneMethodTest";
LogEntry clonedEntry = (LogEntry)entry.Clone();
Assert.AreEqual(entry.ActivityIdString, clonedEntry.ActivityIdString);
Assert.AreEqual(entry.Categories.Count, clonedEntry.Categories.Count);
Assert.AreEqual(entry.EventId, clonedEntry.EventId);
Assert.AreEqual(entry.ExtendedProperties.Count, clonedEntry.ExtendedProperties.Count);
Assert.AreEqual(entry.Message, clonedEntry.Message);
Assert.AreEqual(entry.Priority, clonedEntry.Priority);
Assert.AreEqual(entry.ProcessId, clonedEntry.ProcessId);
Assert.AreEqual(entry.ProcessName, clonedEntry.ProcessName);
Assert.AreEqual(entry.Severity, clonedEntry.Severity);
Assert.AreEqual(entry.TimeStamp, clonedEntry.TimeStamp);
Assert.AreEqual(entry.TimeStampString, clonedEntry.TimeStampString);
Assert.AreEqual(entry.Title, clonedEntry.Title);
Assert.AreEqual(entry.Win32ThreadId, clonedEntry.Win32ThreadId);
Assert.AreEqual(entry.ManagedThreadName, clonedEntry.ManagedThreadName);
Assert.AreEqual(entry.MachineName, clonedEntry.MachineName);
Assert.AreEqual(entry.ErrorMessages, clonedEntry.ErrorMessages);
Assert.AreEqual(entry.AppDomainName, clonedEntry.AppDomainName);
clonedEntry.Categories.Add("Debug");
clonedEntry.ExtendedProperties.Add("key2", "value2");
clonedEntry.ActivityId = new Guid("EEEEFFFFEEEEFFFFEEEEFFFFEEEEFFFF");
Assert.IsTrue(entry.Categories.Count == 1);
Assert.IsTrue(clonedEntry.Categories.Count == 2);
Assert.IsTrue(entry.ExtendedProperties.Count == 1);
Assert.IsTrue(clonedEntry.ExtendedProperties.Count == 2);
Assert.IsFalse(entry.ActivityIdString == clonedEntry.ActivityIdString);
}
示例6: ValidateParameters
private bool ValidateParameters(LogEntry logEntry)
{
bool valid = true;
DatabaseSinkData databaseSinkData = loggingConfigurationView.GetSinkData(ConfigurationName) as DatabaseSinkData;
if (databaseSinkData == null)
{
valid = false;
}
if (databaseSinkData.DatabaseInstanceName == null ||
databaseSinkData.DatabaseInstanceName.Length == 0)
{
valid = false;
}
if (databaseSinkData.StoredProcName == null ||
databaseSinkData.StoredProcName.Length == 0)
{
valid = false;
}
if (!valid)
{
logEntry.AddErrorMessage(SR.DatabaseSinkMissingParameters);
this.defaultSink.SendMessage(logEntry);
}
return valid;
}
示例7: SendMessageCore
/// <summary>
/// Send a log entry message via email.
/// </summary>
/// <param name="log"><see cref="LogEntry"></see> included in email message</param>
protected override void SendMessageCore(LogEntry log)
{
if (ValidateParameters(log))
{
try
{
EmailLogEntry(log, Formatter);
}
catch (Exception e)
{
log.AddErrorMessage(SR.SinkFailure(e.ToString()));
throw;
}
catch
{
log.AddErrorMessage(SR.SinkFailure(SR.UnknownError));
}
}
}
示例8: ValidateParameters
private bool ValidateParameters(LogEntry log)
{
EmailSinkData emailSinkData = GetEmailSinkDataFromView();
bool valid = true;
if (emailSinkData.ToAddress == null ||
emailSinkData.ToAddress.Length == 0)
{
valid = false;
}
if (emailSinkData.FromAddress == null ||
emailSinkData.FromAddress.Length == 0)
{
valid = false;
}
if (emailSinkData.SmtpServer == null ||
emailSinkData.SmtpServer.Length == 0)
{
valid = false;
}
if (!valid)
{
string error = SR.EmailSinkMissingParameters;
log.AddErrorMessage(error);
this.defaultSink.SendMessage(log);
}
return valid;
}
示例9: ValidateParameters
private bool ValidateParameters(LogEntry logEntry)
{
FlatFileSinkData flatFileSinkData = GetFlatFileSinkDataFromCursor();
bool valid = true;
if (flatFileSinkData.Header == null)
{
flatFileSinkData.Header = "";
}
if (flatFileSinkData.Footer == null)
{
flatFileSinkData.Footer = "";
}
if (flatFileSinkData.FileName == null || flatFileSinkData.FileName.Length == 0)
{
valid = false;
logEntry.AddErrorMessage(SR.FileSinkMissingConfiguration);
this.defaultSink.SendMessage(logEntry);
}
return valid;
}
示例10: SendMessageCore
/// <summary>
/// Append the log entry to the configured text file.
/// </summary>
/// <param name="logEntry"><see cref="LogEntry"></see> to be appended to logging file</param>
protected override void SendMessageCore(LogEntry logEntry)
{
if (ValidateParameters(logEntry))
{
try
{
webservice.Logging ws = new webservice.Logging();
ws.Url = this.wsSinkData.Url;
webservice.WSLogEntry wsLogEntry = new webservice.WSLogEntry();
wsLogEntry.Message = logEntry.Message;
wsLogEntry.Priority = logEntry.Priority;
wsLogEntry.Category = logEntry.Category;
wsLogEntry.EventId = logEntry.EventId;
wsLogEntry.Severity = (webservice.Severity)Enum.Parse(typeof(webservice.Severity), logEntry.Severity.ToString());
wsLogEntry.Title = logEntry.Title;
wsLogEntry.ExtendedProperties = WSLogEntry.ToJaggedArray((Hashtable)logEntry.ExtendedProperties);
ws.Log(wsLogEntry);
}
catch (Exception e)
{
logEntry.AddErrorMessage(SR.SinkFailure(e.ToString()));
throw;
}
catch
{
logEntry.AddErrorMessage(SR.SinkFailure(SR.UnknownError));
}
}
}
示例11: ValidateParameters
private bool ValidateParameters(LogEntry logEntry)
{
wsSinkData = GetWSSinkDataFromCursor();
bool valid = true;
if (wsSinkData.Url.Length > 0)
{
valid = false;
logEntry.AddErrorMessage(SR.WSSinkMissingConfiguration);
this.defaultSink.SendMessage(logEntry);
}
try
{
Uri testUrl = new Uri(wsSinkData.Url);
}
catch
{
valid = false;
logEntry.AddErrorMessage(SR.WSSinkMissingConfiguration);
this.defaultSink.SendMessage(logEntry);
}
return valid;
}
示例12: WriteEntryWithMessages
public void WriteEntryWithMessages()
{
SetInProcDistributionStrategy();
LogEntry log = new LogEntry();
log.Category = "AppTest";
log.Message = "My Body";
log.Title = "My Header";
log.EventId = 25;
log.Severity = Severity.Warning;
log.Priority = loggingSettings.MinimumPriority;
log.AddErrorMessage("hey");
log.AddErrorMessage("yes");
Logger.Write(log);
string actual = CommonUtil.GetLastEventLogEntryCustom();
string expected = "yes\r\n\r\nhey";
int pos = actual.IndexOf(expected);
Assert.IsTrue(pos > -1);
}
示例13: ValidateQueuePath
private bool ValidateQueuePath(LogEntry log)
{
MsmqSinkData msmqSinkData = GetMsmqSinkDataFromCursor();
bool valid = true;
if (msmqSinkData.QueuePath == null || msmqSinkData.QueuePath.Length == 0)
{
valid = false;
log.AddErrorMessage(SR.ExceptionMsmqSinkMissingConfiguration);
this.defaultSink.SendMessage(log);
}
return valid;
}
示例14: SendMessage
/// <summary>
/// Write the log entry to the configured event log.
/// </summary>
/// <param name="logEntry"><see cref="LogEntry"></see> to be written to the event log</param>
public void SendMessage(LogEntry logEntry)
{
try
{
short categoryID = GetCategoryId(logEntry);
logEntry.AddErrorMessage(SR.DefaultLogDestinationMessage);
TextFormatter formatter = formatter = new TextFormatter(new TextFormatterData());
string message = FormatEntry(formatter, logEntry);
EventLog.WriteEntry(
eventLogSourceName,
message,
SeverityMap.GetEventLogEntryType(logEntry.Severity),
logEntry.EventId,
categoryID);
LoggingLogDeliveryFailureEvent.Fire(message);
}
catch (Exception e)
{
throw new LoggingException(SR.DefaultLogDestinationFailed, e);
}
catch
{
throw new LoggingException(SR.DefaultLogDestinationFailed);
}
}
示例15: SendMessageCore
/// <summary>
/// Write the log entry to the configured event log.
/// </summary>
/// <param name="logEntry"><see cref="LogEntry"></see> to be logged to event log</param>
protected override void SendMessageCore(LogEntry logEntry)
{
EventLogSinkData eventLogSinkData = GetEventLogSinkDataFromCursor();
short categoryId = defaultSink.GetCategoryId(logEntry);
if (ValidateParameters(logEntry))
{
try
{
using (EventLog eventLog = new EventLog(eventLogSinkData.EventLogName, ".", eventLogSinkData.EventSourceName))
{
eventLog.WriteEntry(
FormatEntry(logEntry),
SeverityMap.GetEventLogEntryType(logEntry.Severity),
logEntry.EventId,
categoryId);
}
}
catch (Exception e)
{
logEntry.AddErrorMessage(SR.SinkFailure(e.ToString()));
throw;
}
catch
{
logEntry.AddErrorMessage(SR.SinkFailure(SR.UnknownError));
throw;
}
}
}