Using .NET logging frameworks or calling the API Stay organized with collections Save and categorize content based on your preferences.
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.V2to 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 theGoogle.Cloud.Diagnostics libraries for .NET.
- For applications that target ASP.NET Core 3 or later, use the
Google.Cloud.Diagnostics.AspNetCore3library. See theGoogle.Cloud.Diagnostics.AspNetCore3documentation for more information and examples. - For applications that target earlier versions of ASP.NET Core, use the
Google.Cloud.Diagnostics.AspNetCorelibrary. See theGoogle.Cloud.Diagnostics.AspNetCoredocumentation for more information and examples. - For applications that target non ASP.NET Core platforms, use the
Google.Cloud.Diagnostics.Commonlibrary. See theGoogle.Cloud.Diagnostics.Commondocumentation for more information and examples.
Use a Google Log4Net provider
TheGoogle.Cloud.Logging.Log4Net library implements a Log4Net provider forCloud Logging. For examples that show how to configure and usethis library, see theGoogle.Cloud.Logging.Log4Net documentation.
UseGoogle.Cloud.Logging.V2 to directly call the Logging API
You can also write logs by calling the Cloud Logging API usingtheGoogle.Cloud.Logging.V2 client library. You can install this library fromNuGet.
After theGoogle.Cloud.Logging.V2 client library is installed, you canstart sending your application's logs to Cloud Logging. For example, youmight customize the following method and add it to your application code.To view the full sample, clickmore_vertMore,and then selectView on GitHub.
privatevoidWriteLogEntry(stringlogId){varclient=LoggingServiceV2Client.Create();LogNamelogName=newLogName(s_projectId,logId);varjsonPayload=newStruct(){Fields={{"name",Value.ForString("King Arthur")},{"quest",Value.ForString("Find the Holy Grail")},{"favorite_color",Value.ForString("Blue")}}};LogEntrylogEntry=newLogEntry{LogNameAsLogName=logName,Severity=LogSeverity.Info,JsonPayload=jsonPayload};MonitoredResourceresource=newMonitoredResource{Type="global"};IDictionary<string,string>entryLabels=newDictionary<string,string>{{"size","large"},{"color","blue"}};client.WriteLogEntries(logName,resource,entryLabels,new[]{logEntry},_retryAWhile);Console.WriteLine($"Created log entry in log-id: {logId}.");}Write some logging code that callsWriteLogEntry(). The resulting log entrywill be in the Logs Explorer under theGlobal resource.
In the Google Cloud console, go to theLogs Explorer page:
If you use the search bar to find this page, then select the result whose subheading isLogging.
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
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.