public static void RegisterGlobalFilters(GlobalFilterCollection filters) { // To enable Google Cloud Stackdriver Logging and Error Reporting // while running on your local machine edit Web.config and uncomment // the <projectId> value under the <log4net> section. Ensure that // the <projectId> is set to a valid Google Cloud Project Id. // Otherwise, the features will only work once deployed to GCP. string projectId = Google.Api.Gax.Platform.Instance().GceDetails?.ProjectId ?? GetProjectIdFromConfig(); if (!string.IsNullOrEmpty(projectId)) { var serviceName = ConfigurationManager.AppSettings["google_error_reporting:serviceName"]; var version = ConfigurationManager.AppSettings["google_error_reporting:version"]; // Add a catch all to log all uncaught exceptions to Stackdriver Error Reporting. filters.Add(ErrorReportingExceptionFilter.Create(projectId, serviceName, version)); // Retrieve a logger for this context. ILog log = LogManager.GetLogger(typeof(FilterConfig)); // Log confirmation of set-up to Google Stackdriver Error Reporting. log.Info("Stackdriver Error Reporting enabled: https://console.cloud.google.com/errors/"); } else { // Retrieve a logger for this context. ILog log = LogManager.GetLogger(typeof(FilterConfig)); // Log warning of missing config for Google Stackdriver Error Reporting. log.Warn("Stackdriver Error Reporting not enabled. ProjectId missing from configuration."); } filters.Add(new HandleErrorAttribute()); }
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { // To enable Google Cloud Stackdrive Logging and Error Reporting // while running on your local machine edit Web.config and uncomment // the <projectId> value under the <log4net> section. Ensure that // the <projectId> is set to a valid Google Cloud Project Id. // [START error_reporting] // Check to ensure that projectId has been changed from placeholder value. var section = (XmlElement)ConfigurationManager.GetSection("log4net"); var projectIdElement = (XmlElement)section.GetElementsByTagName("projectId").Item(0); string projectId = Google.Api.Gax.Platform.Instance().GceDetails?.ProjectId ?? projectIdElement?.Attributes["value"]?.Value; if (string.IsNullOrEmpty(projectId)) { throw new Exception("The logging and error reporting libraries need a project ID. " + "Update Web.config and add a <projectId> entry in the <log4net> section."); } var serviceName = ConfigurationManager.AppSettings["google_error_reporting:serviceName"]; var version = ConfigurationManager.AppSettings["google_error_reporting:version"]; // Add a catch all to log all uncaught exceptions to Stackdriver Error Reporting. filters.Add(ErrorReportingExceptionFilter.Create(projectId, serviceName, version)); // [END error_reporting] filters.Add(new HandleErrorAttribute()); }
// End sample // Sample: RegisterExceptionLoggerMvc public static void RegisterGlobalFilters(GlobalFilterCollection filters) { string projectId = "[Google Cloud Platform project ID]"; string serviceName = "[Name of service]"; string version = "[Version of service]"; // Add a catch all for the uncaught exceptions. filters.Add(ErrorReportingExceptionFilter.Create(projectId, serviceName, version)); }
public void Log() { ExceptionContext context = CreateSimpleContext(); var mockContextLogger = new Mock <IContextExceptionLogger>(); var filter = new ErrorReportingExceptionFilter(mockContextLogger.Object); filter.OnException(context); mockContextLogger.Verify(cl => cl.Log(context.Exception, It.IsAny <ExceptionContextWrapper>())); }
public void Log_Simple() { var mockConsumer = new Mock <IConsumer <ReportedErrorEvent> >(); mockConsumer.Setup(c => c.Receive(s_matcher.IsSimpleContext())); ErrorReportingExceptionFilter filter = CreateFilter(mockConsumer.Object); filter.OnException(CreateSimpleContext()); mockConsumer.VerifyAll(); }
public void Log_Simple() { Mock <ReportErrorsServiceClient> mockClient = new Mock <ReportErrorsServiceClient>(); mockClient.Setup(client => client.ReportErrorEvent(ProjectName, IsSimpleContext(), null)); ErrorReportingExceptionFilter filter = CreateFilter(mockClient.Object); filter.OnException(CreateSimpleContext()); mockClient.VerifyAll(); }
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(ErrorReportingExceptionFilter.Create("cloud-sharp-work", "service", "version")); filters.Add(new HandleErrorAttribute()); }
private ErrorReportingExceptionFilter CreateFilter(ReportErrorsServiceClient client) => ErrorReportingExceptionFilter.Create(client, ProjectId, ServiceName, Version);