Stay organized with collections Save and categorize content based on your preferences.


Google.Cloud.Logging.Console is a package providing a custom console formatter designed to be used with Cloud Logging.


Install the Google.Cloud.Logging.Console package from NuGet. Add it to your project in the normal way (for example by right-clicking on the project in Visual Studio and choosing "Manage NuGet Packages...").

Registering the formatter

After installing the NuGet package, the formatter can be installed using the AddGoogleCloudConsole extension method:

using Google.Cloud.Logging.Console;
var builder = WebApplication.CreateBuilder(args);

Additional options can be provided either in appsettings.json or in the extension method call. For example, to enable scopes to be logged, you could change the above code to:

using Google.Cloud.Logging.Console;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddGoogleCloudConsole(options => options.IncludeScopes = true);

Formatter output

The formatter writes JSON entries in the format expected by Cloud Logging. In particular, it uses the following JSON property names:

  • message: the formatted log message
  • severity: the log entry severity
  • category: the logger category
  • exception: the exception stack trace, if any
  • format_parameters: the format parameters for the message, if any
  • scopes: the scope information for the log entry, if the IncludeScopes option is enabled and there is scope information available

No timestamp is included in the JSON, as this is automatically picked up by the logging agent.

Most log entry severity mappings are obvious, but the ASP.NET Core LogLevel.Trace level maps to DEBUG in Cloud Logging.

When viewing the log entries in the Logs Explorer, the severity is shown in the root of the entry. Other aspects are within the jsonPayload property.