本文整理汇总了C#中Mindscape.Raygun4Net.Messages.RaygunMessage类的典型用法代码示例。如果您正苦于以下问题:C# RaygunMessage类的具体用法?C# RaygunMessage怎么用?C# RaygunMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RaygunMessage类属于Mindscape.Raygun4Net.Messages命名空间,在下文中一共展示了RaygunMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnSendingMessage
// Returns true if the message can be sent, false if the sending is canceled.
protected bool OnSendingMessage(RaygunMessage raygunMessage)
{
bool result = true;
if (!_handlingRecursiveErrorSending)
{
EventHandler<RaygunSendingMessageEventArgs> handler = SendingMessage;
if (handler != null)
{
RaygunSendingMessageEventArgs args = new RaygunSendingMessageEventArgs(raygunMessage);
try
{
handler(this, args);
}
catch (Exception e)
{
// Catch and send exceptions that occur in the SendingMessage event handler.
// Set the _handlingRecursiveErrorSending flag to prevent infinite errors.
_handlingRecursiveErrorSending = true;
Send(e);
_handlingRecursiveErrorSending = false;
}
result = !args.Cancel;
}
}
return result;
}
示例2: OnSendingMessage
// Returns true if the message can be sent, false if the sending is canceled.
protected bool OnSendingMessage(RaygunMessage raygunMessage)
{
bool result = true;
EventHandler<RaygunSendingMessageEventArgs> handler = SendingMessage;
if (handler != null)
{
RaygunSendingMessageEventArgs args = new RaygunSendingMessageEventArgs(raygunMessage);
handler(this, args);
result = !args.Cancel;
}
return result;
}
示例3: Emit
/// <summary>
/// Emit the provided log event to the sink.
/// </summary>
/// <param name="logEvent">The log event to write.</param>
public void Emit(LogEvent logEvent)
{
//Include the log level as a tag.
var tags = _tags.Concat(new []{logEvent.Level.ToString()}).ToList();
var properties = logEvent.Properties
.Select(pv => new { Name = pv.Key, Value = RaygunPropertyFormatter.Simplify(pv.Value) })
.ToDictionary(a => a.Name, b => b.Value);
// Add the message
properties.Add("RenderedLogMessage", logEvent.RenderMessage(_formatProvider));
properties.Add("LogMessageTemplate", logEvent.MessageTemplate.Text);
// Create new message
var raygunMessage = new RaygunMessage
{
OccurredOn = logEvent.Timestamp.UtcDateTime
};
// Add exception when available
if (logEvent.Exception != null)
raygunMessage.Details.Error = new RaygunErrorMessage(logEvent.Exception);
// Add user when requested
if (!String.IsNullOrWhiteSpace(_userNameProperty) &&
logEvent.Properties.ContainsKey(_userNameProperty) &&
logEvent.Properties[_userNameProperty] != null)
{
raygunMessage.Details.User = new RaygunIdentifierMessage(logEvent.Properties[_userNameProperty].ToString());
}
// Add version when requested
if (!String.IsNullOrWhiteSpace(_applicationVersionProperty) &&
logEvent.Properties.ContainsKey(_applicationVersionProperty) &&
logEvent.Properties[_applicationVersionProperty] != null)
{
raygunMessage.Details.Version = logEvent.Properties[_applicationVersionProperty].ToString();
}
// Build up the rest of the message
raygunMessage.Details.Environment = new RaygunEnvironmentMessage();
raygunMessage.Details.Tags = tags;
raygunMessage.Details.UserCustomData = properties;
raygunMessage.Details.MachineName = Environment.MachineName;
if (HttpContext.Current != null)
raygunMessage.Details.Request = new RaygunRequestMessage(HttpContext.Current.Request, null);
// Submit
_client.SendInBackground(raygunMessage);
}
示例4: CanNotSendIfExcludingStatusCode_MultipleCodes
public void CanNotSendIfExcludingStatusCode_MultipleCodes()
{
RaygunSettings.Settings.ExcludeHttpStatusCodesList = "400, 404, 501";
RaygunMessage message = new RaygunMessage
{
Details = new RaygunMessageDetails
{
Response = new RaygunResponseMessage
{
StatusCode = 404
}
}
};
Assert.IsFalse(_client.ExposeCanSend(message));
}
示例5: CanSendIfMessageIsNull
public void CanSendIfMessageIsNull()
{
RaygunSettings.Settings.ExcludeHttpStatusCodesList = null;
// Null message
Assert.IsTrue(_client.ExposeCanSend(null));
// Null message details
Assert.IsTrue(_client.ExposeCanSend(new RaygunMessage()));
RaygunMessage message = new RaygunMessage
{
Details = new RaygunMessageDetails()
};
// Null message response
Assert.IsTrue(_client.ExposeCanSend(message));
}
示例6: Send
/// <summary>
/// Posts a RaygunMessage to the Raygun.io api endpoint.
/// </summary>
/// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property
/// set to a valid DateTime and as much of the Details property as is available.</param>
public void Send(RaygunMessage raygunMessage)
{
if (ValidateApiKey())
{
if (HasInternetConnection)
{
using (var client = new WebClient())
{
client.Headers.Add("X-ApiKey", _apiKey);
client.Encoding = System.Text.Encoding.UTF8;
try
{
var message = SimpleJson.SerializeObject(raygunMessage);
client.UploadString(RaygunSettings.Settings.ApiEndpoint, message);
System.Diagnostics.Debug.WriteLine("Sending message to Raygun.io");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message));
try
{
SaveMessage(SimpleJson.SerializeObject(raygunMessage));
System.Diagnostics.Debug.WriteLine("Exception has been saved to the device to try again later.");
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(string.Format("Error saving Exception to device {0}", e.Message));
}
}
}
}
else
{
try
{
var message = SimpleJson.SerializeObject(raygunMessage);
SaveMessage(message);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(string.Format("Error saving Exception to device {0}", ex.Message));
}
}
}
}
示例7: Send
/// <summary>
/// Posts a RaygunMessage to the Raygun.io api endpoint.
/// </summary>
/// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property
/// set to a valid DateTime and as much of the Details property as is available.</param>
public override void Send(RaygunMessage raygunMessage)
{
bool canSend = OnSendingMessage(raygunMessage);
if (canSend)
{
string message = null;
try
{
message = SimpleJson.SerializeObject(raygunMessage);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(string.Format("Error serializing exception {0}", ex.Message));
if (RaygunSettings.Settings.ThrowOnError)
{
throw;
}
}
if (message != null)
{
try
{
Send(message);
}
catch (Exception ex)
{
SaveMessage(message);
System.Diagnostics.Debug.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message));
if (RaygunSettings.Settings.ThrowOnError)
{
throw;
}
}
SendStoredMessages();
}
}
}
示例8: Send
/// <summary>
/// Posts a RaygunMessage to the Raygun.io api endpoint.
/// </summary>
/// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property
/// set to a valid DateTime and as much of the Details property as is available.</param>
public void Send(RaygunMessage raygunMessage)
{
bool calledFromUnhandled = IsCalledFromApplicationUnhandledExceptionHandler();
Send(raygunMessage, calledFromUnhandled, false);
}
示例9: Send
/// <summary>
/// Posts a RaygunMessage to the Raygun.io api endpoint.
/// </summary>
/// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property
/// set to a valid DateTime and as much of the Details property as is available.</param>
public override void Send(RaygunMessage raygunMessage)
{
if (ValidateApiKey())
{
bool canSend = OnSendingMessage(raygunMessage);
if (canSend)
{
string message = null;
try
{
message = SimpleJson.SerializeObject(raygunMessage);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(string.Format("Error Serializing Exception {0}", ex.Message));
}
if (!String.IsNullOrWhiteSpace(message))
{
using (var client = new WebClient())
{
client.Headers.Add("X-ApiKey", _apiKey);
client.Headers.Add("content-type", "application/json; charset=utf-8");
client.Encoding = System.Text.Encoding.UTF8;
try
{
client.UploadString(RaygunSettings.Settings.ApiEndpoint, message);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message));
}
}
}
}
}
}
示例10: SendOrSave
private async Task SendOrSave(RaygunMessage raygunMessage)
{
if (ValidateApiKey())
{
bool canSend = OnSendingMessage(raygunMessage);
if (canSend)
{
try
{
string message = SimpleJson.SerializeObject(raygunMessage);
if (InternetAvailable())
{
await SendMessage(message);
}
else
{
await SaveMessage(message);
}
}
catch (Exception ex)
{
Debug.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message));
}
}
}
}
示例11: RaygunMessageBuilderBase
protected RaygunMessageBuilderBase()
{
_raygunMessage = new RaygunMessage();
}
示例12: SendInBackground
/// <summary>
/// Asynchronously transmits a message to Raygun.
/// </summary>
/// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property
/// set to a valid DateTime and as much of the Details property as is available.</param>
public Task SendInBackground(RaygunMessage raygunMessage)
{
return Task.Run(() => Send(raygunMessage));
}
示例13: OnCustomGroupingKey
protected async Task<string> OnCustomGroupingKey(Exception exception, RaygunMessage message)
{
string result = null;
if (!_handlingRecursiveGrouping)
{
var handler = CustomGroupingKey;
if (handler != null)
{
var args = new RaygunCustomGroupingKeyEventArgs(exception, message);
try
{
handler(this, args);
}
catch (Exception e)
{
_handlingRecursiveGrouping = true;
await SendAsync(e, null, null, null);
_handlingRecursiveGrouping = false;
}
result = args.CustomGroupingKey;
}
}
return result;
}
示例14: FilterShouldPreventSend
protected bool FilterShouldPreventSend(RaygunMessage raygunMessage)
{
return MessageSendFilter != null && !MessageSendFilter(raygunMessage);
}
示例15: SendAsync
/// <summary>
/// Asynchronously sends a RaygunMessage to the Raygun.io api endpoint.
/// It is best to call this method within a try/catch block.
/// If the application is crashing due to an unhandled exception, use the synchronous methods instead.
/// </summary>
/// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property
/// set to a valid DateTime and as much of the Details property as is available.</param>
public async Task SendAsync(RaygunMessage raygunMessage)
{
await SendOrSave(raygunMessage);
}