/// <summary> /// Determines if this log message should be sent to Bugsnag based on the /// configured rules around unique log messages with a time period. /// </summary> /// <param name="unityLogMessage"></param> /// <returns></returns> public bool ShouldSend(UnityLogMessage unityLogMessage) { bool shouldSend; lock (_lock) { shouldSend = !Counter.ContainsKey(unityLogMessage); if (shouldSend) { Counter.Add(unityLogMessage, 0); } else { if (unityLogMessage.CreatedAt > FlushAt) { Counter.Clear(); FlushAt = DateTime.UtcNow.Add(UniqueLogsTimePeriod); shouldSend = true; } } } return(shouldSend); }
public bool ShouldSend(UnityLogMessage unityLogMessage) { var type = unityLogMessage.Type; lock (_lock) { if (MaximumTypePerTimePeriod.ContainsKey(type)) { if (CurrentCounts.ContainsKey(type)) { CurrentCounts[type]++; } else { CurrentCounts[type] = 1; } if (CurrentCounts[type] > MaximumTypePerTimePeriod[type]) { if (unityLogMessage.CreatedAt > FlushAt) { CurrentCounts.Clear(); FlushAt = DateTime.UtcNow.Add(MaximumLogsTimePeriod); return(true); } return(false); } } } return(true); }
/// <summary> /// Notify a Unity log message if it the client has been configured to /// notify at the specified level, if not leave a breadcrumb with the log /// message. /// </summary> /// <param name="condition"></param> /// <param name="stackTrace"></param> /// <param name="logType"></param> void Notify(string condition, string stackTrace, LogType logType) { if (Configuration.AutoNotify && logType.IsGreaterThanOrEqualTo(Configuration.NotifyLevel)) { var logMessage = new UnityLogMessage(condition, stackTrace, logType); if (UniqueCounter.ShouldSend(logMessage)) { if (LogTypeCounter.ShouldSend(logMessage)) { var severity = Configuration.LogTypeSeverityMapping.Map(logType); var backupStackFrames = new System.Diagnostics.StackTrace(1, true).GetFrames(); var forceUnhandled = logType == LogType.Exception && !Configuration.ReportUncaughtExceptionsAsHandled; var exception = Exception.FromUnityLogMessage(logMessage, backupStackFrames, severity, forceUnhandled); Notify(new Exception[] { exception }, exception.HandledState, null, logType); } } } else { Breadcrumbs.Leave(logType.ToString(), BreadcrumbType.Log, new Dictionary <string, string> { { "message", condition }, }); } }