Exemplo n.º 1
0
 // IErrorReportingClient /////////////////////////////////////////////////////////////////////
 public async Task SendReportAsync(Exception ex)
 {
     await _client.ReportErrorEventAsync(_projectName, new ReportedErrorEvent()
     {
         Message        = ex.ToString(),
         ServiceContext = new ServiceContext()
         {
             Service = _serviceName,
             Version = _serviceVersion
         }
     });
 }
 public async Task ReportErrorEventAsync()
 {
     // Snippet: ReportErrorEventAsync(string,ReportedErrorEvent,CallSettings)
     // Additional: ReportErrorEventAsync(string,ReportedErrorEvent,CancellationToken)
     // Create client
     ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.Create();
     // Initialize request argument(s)
     string formattedProjectName = ReportErrorsServiceClient.FormatProjectName("[PROJECT]");
     ReportedErrorEvent @event = new ReportedErrorEvent();
     // Make the request
     ReportErrorEventResponse response = await reportErrorsServiceClient.ReportErrorEventAsync(formattedProjectName, @event);
     // End snippet
 }
Exemplo n.º 3
0
        /// <inheritdoc />
        public async Task ReceiveAsync(
            IEnumerable <ReportedErrorEvent> events, CancellationToken cancellationToken = default(CancellationToken))
        {
            GaxPreconditions.CheckNotNull(events, nameof(events));
            if (!events.Any())
            {
                return;
            }

            foreach (var errorEvent in events)
            {
                await _client.ReportErrorEventAsync(_projectName, errorEvent, cancellationToken).ConfigureAwait(false);
            }
        }
        /// <summary>Snippet for ReportErrorEventAsync</summary>
        public async Task ReportErrorEventResourceNamesAsync()
        {
            // Snippet: ReportErrorEventAsync(ProjectName, ReportedErrorEvent, CallSettings)
            // Additional: ReportErrorEventAsync(ProjectName, ReportedErrorEvent, CancellationToken)
            // Create client
            ReportErrorsServiceClient reportErrorsServiceClient = await ReportErrorsServiceClient.CreateAsync();

            // Initialize request argument(s)
            ProjectName        projectName = ProjectName.FromProject("[PROJECT]");
            ReportedErrorEvent @event      = new ReportedErrorEvent();
            // Make the request
            ReportErrorEventResponse response = await reportErrorsServiceClient.ReportErrorEventAsync(projectName, @event);

            // End snippet
        }
        public async Task ReportErrorEventAsync_RequestObject()
        {
            // Snippet: ReportErrorEventAsync(ReportErrorEventRequest,CallSettings)
            // Create client
            ReportErrorsServiceClient reportErrorsServiceClient = await ReportErrorsServiceClient.CreateAsync();

            // Initialize request argument(s)
            ReportErrorEventRequest request = new ReportErrorEventRequest
            {
                ProjectNameAsProjectName = new ProjectName("[PROJECT]"),
                Event = new ReportedErrorEvent(),
            };
            // Make the request
            ReportErrorEventResponse response = await reportErrorsServiceClient.ReportErrorEventAsync(request);

            // End snippet
        }
Exemplo n.º 6
0
        public void CreateReportErrorEventAsync(Exception ex, string userid, string service, string version, HttpContext httpContext = null)
        {
            ProjectName projectName = new ProjectName(projectId);

            StackTrace stackTrace = new StackTrace(ex, true);
            StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1);

            ReportedErrorEvent error = new ReportedErrorEvent
            {
                Context = new ErrorContext
                {
                    ReportLocation = new SourceLocation
                    {
                        FilePath     = stackFrame.GetFileName(),
                        FunctionName = stackFrame.GetMethod().Name,
                        LineNumber   = stackFrame.GetFileLineNumber(),
                    },
                    User = userid
                },
                // If this is a stack trace, the service will parse it.
                Message = ex.Message,

                EventTime      = Timestamp.FromDateTime(DateTime.UtcNow),
                ServiceContext = new ServiceContext
                {
                    Service = service,
                    Version = version
                }
            };

            if (httpContext != null)
            {
                HttpRequestContext httpRequest = new HttpRequestContext
                {
                    Method   = httpContext.Request.Method,
                    Referrer = httpContext.Request.Path,
                    RemoteIp = httpContext.Connection.RemoteIpAddress.ToString(),
                    Url      = httpContext.Request.Path
                };

                error.Context.HttpRequest = httpRequest;
            }

            client.ReportErrorEventAsync(projectName, error);
        }
 /// <inheritdoc />
 public override async Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
 {
     ReportedErrorEvent        errorEvent = CreateReportRequest(context);
     ReportErrorsServiceClient client     = await _clientTask;
     await client.ReportErrorEventAsync(_projectResourceName, errorEvent);
 }
Exemplo n.º 8
0
        /// <inheritdoc />
        public override Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
        {
            ReportedErrorEvent errorEvent = CreateReportRequest(context);

            return(_client.ReportErrorEventAsync(_projectResourceName, errorEvent));
        }