Show / Hide Table of Contents

Class GoogleWebApiExceptionLogger

Google Cloud Error Reporting Logger for Web API applications. Reports exceptions to Stackdriver Error Reporting API.

Inheritance
System.Object
GoogleWebApiExceptionLogger
Implements
IWebApiExceptionLogger
System.IDisposable
Inherited Members
System.Object.ToString()
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Cloud.Diagnostics.AspNet
Assembly: Google.Cloud.Diagnostics.AspNet.dll
Syntax
public class GoogleWebApiExceptionLogger : IWebApiExceptionLogger, IDisposable
Examples
string projectId = "[Google Cloud Platform project ID]";
string serviceName = "[Name of service]";
string version = "[Version of service]";
var exceptionLogger = GoogleWebApiExceptionLogger.Create(projectId, serviceName, version);

try
{
    string scores = File.ReadAllText(@"C:\Scores.txt");
    Console.WriteLine(scores);
}
catch (IOException e)
{
    exceptionLogger.Log(e, ActionContext);
}

Methods

Create(String, String, ErrorReportingOptions)

Creates an instance of GoogleWebApiExceptionLogger.

Can be used when running on Google App Engine or Google Compute Engine. The Google Cloud Platform project to report errors to will detected from the current platform.

Declaration
public static GoogleWebApiExceptionLogger Create(string serviceName, string version, ErrorReportingOptions options = null)
Parameters
Type Name Description
System.String serviceName

An identifier of the service, such as the name of the executable or job. May be null.

System.String version

Represents the source code version that the developer provided. May be null.

ErrorReportingOptions options

Optional, error reporting options.

Returns
Type Description
GoogleWebApiExceptionLogger

Create(String, String, String, ErrorReportingOptions)

Creates an instance of GoogleWebApiExceptionLogger.

Declaration
public static GoogleWebApiExceptionLogger Create(string projectId, string serviceName, string version, ErrorReportingOptions options = null)
Parameters
Type Name Description
System.String projectId

The Google Cloud Platform project ID. Must not be null.

System.String serviceName

An identifier of the service, such as the name of the executable or job. May be null.

System.String version

Represents the source code version that the developer provided. May be null.

ErrorReportingOptions options

Optional, error reporting options.

Returns
Type Description
GoogleWebApiExceptionLogger

Dispose()

Declaration
public void Dispose()
Implements
System.IDisposable.Dispose()

Log(Exception, HttpActionContext)

Logs an exception that occurred.

Declaration
public void Log(Exception exception, HttpActionContext context = null)
Parameters
Type Name Description
System.Exception exception

The exception to log. Must not be null.

System.Web.Http.Controllers.HttpActionContext context

Optional, the current HTTP action context from which to get HTTP context information. If it is not set, no HTTP context information will be logged alongside exception information.

Implements
IWebApiExceptionLogger.Log(Exception, HttpActionContext)

LogAsync(Exception, HttpActionContext, CancellationToken)

Asynchronously logs an exception that occurred.

Declaration
public Task LogAsync(Exception exception, HttpActionContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
System.Exception exception

The exception to log. Must not be null.

System.Web.Http.Controllers.HttpActionContext context

Optional, the current HTTP action context from which to get HTTP context information. If it is not set, no HTTP context information will be logged alongside exception information.

System.Threading.CancellationToken cancellationToken

Optional, the token to monitor for cancellation requests.

Returns
Type Description
System.Threading.Tasks.Task

A task representing the asynchronous operation.

Implements
IWebApiExceptionLogger.LogAsync(Exception, HttpActionContext, CancellationToken)
Back to top