Ucommerce
  • Ucommerce Next Gen
    • Getting Started
      • Prerequisites
      • Licensing
      • Ucommerce Templates
      • Headless Template
      • MVC Template
    • Headless
      • Postman Collection
      • Headless API Authentication
        • Token endpoint - Authorization Header
        • Authorization Scopes
        • Refreshing the Access Token
      • Reference
        • Cart
        • Cart / Order Line Items
        • Shipment
        • Billing
        • Promotion Codes
        • Price Groups
        • Payment Methods
        • Countries
        • Shipping Methods
        • Catalogs
        • Cart Custom Properties
        • Line Item Custom Properties
        • Orders
        • Views for Cart modifying operations
      • Custom Headless APIs
      • Error Handling
      • Pagination
      • Deprecation
    • Backoffice Authentication
      • Microsoft Entra ID Example
      • Auth0 Authentication Example
    • Definitions
      • What is a Definition
    • Search and indexing
      • Configuration
      • Indexing
        • Index Definitions
        • Facets
        • Indexing Prices
        • Suggestions
        • Custom Data
      • Searching
    • Payment Providers
      • Stripe Provider Integration
      • Implementing a custom payment provider
    • Data Import
    • Miscellaneous
      • Media
      • Price Group Inheritance
      • Price Group Criteria
      • Soft Deletion Of Entities
      • Logging
      • OpenTelemetry
    • Extensions
      • Extending Pipelines
        • Order Processing Pipelines
        • Checkout Pipelines
      • Changing Service Behavior
        • Images
        • Content
      • Custom Headless APIs
      • Extend the Backoffice
        • Custom UI Components
      • Custom Editor UI
      • Custom Promotion Criteria
      • Custom Price Group Criteria
    • How-To
      • Migrate from Classic
        • Common database issues
      • Entities from code
        • Bootstrapping data on startup
        • Product Definitions & Fields
      • Discover pipelines and their tasks
      • Executing a pipeline
    • Integrations
      • Umbraco Media Delivery API
      • App Slices
        • Product Picker
  • Release Notes
  • Contact Us
Powered by GitBook
On this page
  • Writing logs using ILogger<TCategoryName>
  • Providers
  • EF Core queries and sensitive data

Was this helpful?

  1. Ucommerce Next Gen
  2. Miscellaneous

Logging

PreviousSoft Deletion Of EntitiesNextOpenTelemetry

Last updated 3 months ago

Was this helpful?

Good logs make it easier to identify and debug issues with your application at runtime. Ucommerce uses the built-in logging system from ASP.NET to make it simple for you to get and store log messages.

Writing logs using ILogger<TCategoryName>

Getting started with logging in Ucommerce is easy since it uses the built-in logging APIs. You can take a dependency on the ILogger<TCategoryName> interface and dependency injection will inject a logger into your class.

public class MyClass {
    private readonly ILogger<MyClass> _logger;

    public MyClass(ILogger<MyClass> logger) {
        _logger = logger ?? throw new ArgumentNullException(nameof(logger));
    }
...
}

Providers

The default Ucommerce templates don't make any changes from the default . We recommend that you gather logs into a central log store to make discovery and debugging production issues easier.

Examples:

EF Core queries and sensitive data

When debugging issues it can be very useful to see all the values given to, and the structure of, a query created by Entity Framework. Ucommerce makes it easy to set this up for the UcommerceDBContext by setting the Ucommerce.Persistance.SensitiveDataLogging option to true in your appSettings.json file.

{
...
  "Ucommerce": {
    "Persistence":{
      "SensitiveDataLogging": true
    },
...
}

The option activates the following in the database context:

  • Log queries to the console and debug output.

If you are only interested in seeing the queries created you can set the logging level for the Microsoft.EntityFrameworkCore.Database.Command category to Information or lower. This should also work in production as opposed to the above option.

{
...
  "Logging": {
    "LogLevel": {
      "Microsoft.EntityFrameworkCore.Database.Command": "Information"
    }
  },
...
}

logging provider setup
Seq
Application Insights
Datadog
Enables sensitive data logging
Enables detailed errors