public void ShouldLog() { Mock <ReportErrorsServiceClient> mockClient = new Mock <ReportErrorsServiceClient>(); CloudErrorReportingExceptionLogger logger = GetLogger(mockClient.Object); Assert.True(logger.ShouldLog(SimpleContext)); Assert.False(logger.ShouldLog(null)); }
// Sample: RegisterExceptionLogger public static void Register(HttpConfiguration config) { 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. config.Services.Add(typeof(IExceptionLogger), CloudErrorReportingExceptionLogger.Create(projectId, serviceName, version)); }
public void LogAsync() { Mock <ReportErrorsServiceClient> mockClient = new Mock <ReportErrorsServiceClient>(); mockClient.Setup(client => client.ReportErrorEventAsync(FormattedProjectId, IsComplexContext(), null)); CloudErrorReportingExceptionLogger logger = GetLogger(mockClient.Object); logger.LogAsync(CreateComplexContext(), CancellationToken.None); mockClient.VerifyAll(); }
public void Log_Simple() { Mock <ReportErrorsServiceClient> mockClient = new Mock <ReportErrorsServiceClient>(); mockClient.Setup(client => client.ReportErrorEvent(FormattedProjectId, IsSimpleContext(), null)); CloudErrorReportingExceptionLogger logger = GetLogger(mockClient.Object); logger.Log(SimpleContext); mockClient.VerifyAll(); }
// [START register_error_reporting] public static void Register(HttpConfiguration config) { string projectId = "YOUR-PROJECT-ID"; string serviceName = "NAME-OF-YOUR-SERVICE"; string version = "VERSION-OF-YOUR-SERVCICE"; // [START _EXCLUDE] // Check to ensure that projectId has been changed from placeholder value. if (projectId == ("YOUR-PROJECT" + "-ID")) { throw new Exception("Set string projectId above to be your project id."); } // [END _EXCLUDE] // Add a catch all for the uncaught exceptions. config.Services.Add(typeof(IExceptionLogger), CloudErrorReportingExceptionLogger.Create(projectId, serviceName, version)); // [START _EXCLUDE] var emptyDictionary = new HttpRouteValueDictionary(); // Add our one HttpMessageHandler to the root path. config.Routes.MapHttpRoute("index", "", emptyDictionary, emptyDictionary, new HelloWorldHandler()); // [END _EXCLUDE] }
private CloudErrorReportingExceptionLogger GetLogger(ReportErrorsServiceClient client) { return(CloudErrorReportingExceptionLogger.Create(client, ProjectId, ServiceName, Version)); }