public async Task <long> LogCommitStatsAsync(string projectId, string instanceId, string databaseId) { // Commit statistics are logged at level Info by the default logger. // This sample uses a custom logger to access the commit statistics. // See https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Spanner.Data/logging.html // for more information on how to use loggers. var logger = new CommitStatsSampleLogger(); var options = new SessionPoolOptions(); var poolManager = SessionPoolManager.Create(options, logger); var connectionStringBuilder = new SpannerConnectionStringBuilder { ConnectionString = $"Data Source=projects/{projectId}/instances/{instanceId}/databases/{databaseId}", // Set LogCommitStats to true to enable logging commit statistics for all transactions on the connection. // LogCommitStats can also be enabled/disabled for individual Spanner transactions. LogCommitStats = true, SessionPoolManager = poolManager, }; using var connection = new SpannerConnection(connectionStringBuilder); await connection.OpenAsync(); using var cmd = connection.CreateDmlCommand("INSERT Singers (SingerId, FirstName, LastName) VALUES (110, 'Virginia', 'Watson')"); var rowCount = await cmd.ExecuteNonQueryAsync(); var mutationCount = logger._lastCommitResponse.CommitStats.MutationCount; Console.WriteLine($"{rowCount} row(s) inserted..."); Console.WriteLine($"{mutationCount} mutation(s) in transaction..."); return(mutationCount); }
// Creates a SpannerConnection with a specific logger. public SpannerConnection GetConnection(Logger logger) => new SpannerConnection(new SpannerConnectionStringBuilder(ConnectionString) { SessionPoolManager = SessionPoolManager.Create(new V1.SessionPoolOptions(), logger) });
public void Create_UsesDefaultLogger() { var manager = SessionPoolManager.Create(new SessionPoolOptions()); Assert.Same(Logger.DefaultLogger, manager.Logger); }