Freigeben über


CosmosDiagnostics.ToString Methode

Definition

Ruft das Zeichenfolgenfeld CosmosDiagnostics instance im Azure Cosmos DB-Datenbankdienst ab.

public abstract string ToString ();
override this.ToString : unit -> string
Public MustOverride Function ToString () As String

Gibt zurück

Das Zeichenfolgenfeld CosmosDiagnostics instance im Azure Cosmos DB-Datenbankdienst.

Beispiele

Materialisieren Sie die Diagnose erst zum Zeitpunkt der Nutzung, um unnötige Zuordnungen zu vermeiden. Lassen Sie toString nur bei Bedarf aufrufen. Sie können Diagnose abhängig von Latenz oder Fehlern bedingt erfassen:

try
{
    ItemResponse<Book> response = await container.CreateItemAsync<Book>(item: testItem);
    if (response.Diagnostics.GetClientElapsedTime() > ConfigurableSlowRequestTimeSpan)
    {
        // Log the diagnostics and add any additional info necessary to correlate to other logs 
        logger.LogInformation("Operation took longer than expected, Diagnostics: {Diagnostics}");
    }
}
catch (CosmosException cosmosException)
{
    // Log the full exception including the stack trace 
    logger.LogError(cosmosException);
    // The Diagnostics can be logged separately if required.
    logger.LogError("Cosmos DB call failed with {StatusCode}, {SubStatusCode}, Diagnostics: {Diagnostics}", cosmosException.StatusCode, cosmosException.SubStatusCode, cosmosException.Diagnostics);
}

Hinweise

CosmosDiagnostics implementiert eine verzögerte Materialisierung und wird nur materialisiert, wenn ToString() aufgerufen wird.

Gilt für: