Show / Hide Table of Contents

Class GoogleExceptionLogger

Google Cloud Error Reporting Logger. Reports exceptions to Stackdriver Error Reporting API.

Inheritance
System.Object
GoogleExceptionLogger
Implements
IExceptionLogger
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 GoogleExceptionLogger : IExceptionLogger, IDisposable
Examples
string projectId = "[Google Cloud Platform project ID]";
string serviceName = "[Name of service]";
string version = "[Version of service]";
var exceptionLogger = GoogleExceptionLogger.Create(projectId, serviceName, version);

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

Methods

Create(String, String, ErrorReportingOptions)

Creates an instance of GoogleExceptionLogger.

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 GoogleExceptionLogger 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
GoogleExceptionLogger

Create(String, String, String, ErrorReportingOptions)

Creates an instance of GoogleExceptionLogger.

Declaration
public static GoogleExceptionLogger 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
GoogleExceptionLogger

Dispose()

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

Log(Exception, HttpContext)

Logs an exception that occurred.

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

The exception to log. Must not be null.

System.Web.HttpContext context

Optional, the current HTTP context. If unset the current context will be retrieved automatically.

Implements
IExceptionLogger.Log(Exception, HttpContext)

LogAsync(Exception, HttpContext, CancellationToken)

Asynchronously logs an exception that occurred.

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

The exception to log. Must not be null.

System.Web.HttpContext context

Optional, the current HTTP context. If unset the current context will be retrieved automatically.

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
IExceptionLogger.LogAsync(Exception, HttpContext, CancellationToken)
Back to top