There are several ways to use Cloud Logging from your .NET application:
- Use a Google logging provider for .NET's standard logging framework
- Use a Google Log4Net provider
- Use
Google.Cloud.Logging.V2
to directly call the Logging API
Use a Google logging provider for .NET's standard logging framework
You can enable Cloud Logging for .NET applications by using the
Google.Cloud.Diagnostics
libraries for .NET.
- For applications that target ASP.NET Core 3 or later, use the
Google.Cloud.Diagnostics.AspNetCore3
library. See theGoogle.Cloud.Diagnostics.AspNetCore3
documentation for more information and examples. - For applications that target earlier versions of ASP.NET Core, use the
Google.Cloud.Diagnostics.AspNetCore
library. See theGoogle.Cloud.Diagnostics.AspNetCore
documentation for more information and examples. - For applications that target non ASP.NET Core platforms, use the
Google.Cloud.Diagnostics.Common
library. See theGoogle.Cloud.Diagnostics.Common
documentation for more information and examples.
Use a Google Log4Net provider
The
Google.Cloud.Logging.Log4Net
library implements a Log4Net provider for
Cloud Logging. For examples that show how to configure and use
this library, see the
Google.Cloud.Logging.Log4Net
documentation.
Use
Google.Cloud.Logging.V2
to directly call the Logging API
You can also write logs by calling the Cloud Logging API using
the
Google.Cloud.Logging.V2
client library. You can install this library from
NuGet.
After the
Google.Cloud.Logging.V2
client library is installed, you can
start sending your application's logs to Cloud Logging. For example, you
might customize the following method and add it to your application code.
To view the full sample, click more_vert More,
and then select View on GitHub.
Write some logging code that calls WriteLogEntry()
. The resulting log entry
will be in the Logs Explorer under the Global resource.
In the Google Cloud console, go to the Logs Explorer page:
If you use the search bar to find this page, then select the result whose subheading is Logging.
Resources
- For details on the Logs Explorer, see [Using the Logs Explorer][view-ui].
- For ASP.NET Core 3+ applications
- For earlier ASP.NET Core applications
- For non ASP.NET Core applications
- Log4Net Provider
- GitHub: googleapis/google-cloud-dotnet
- GitHub issue tracker