Skip to content

Commit 1c8fae5

Browse files
authored
CSHARP-4278: Unified runner for logging tests (#879)
* CSHARP-4278: Unified runner for logging tests
1 parent 36eb1fe commit 1c8fae5

File tree

144 files changed

+5072
-964
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+5072
-964
lines changed

src/MongoDB.Driver.Core/Core/Clusters/Cluster.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFact
101101

102102
_serverSessionPool = new CoreServerSessionPool(this);
103103

104-
_clusterEventsLogger = loggerFactory.CreateEventsLogger<LogCategories.Cluster>(eventSubscriber, _clusterId);
105-
_serverSelectionEventsLogger = loggerFactory.CreateEventsLogger<LogCategories.ServerSelection>(eventSubscriber, _clusterId);
104+
_clusterEventsLogger = loggerFactory.CreateEventsLogger<LogCategories.Cluster>(eventSubscriber);
105+
_serverSelectionEventsLogger = loggerFactory.CreateEventsLogger<LogCategories.ServerSelection>(eventSubscriber);
106106

107107
ClusterDescription CreateInitialDescription()
108108
{
@@ -166,7 +166,7 @@ protected virtual void Dispose(bool disposing)
166166
{
167167
if (_state.TryChange(State.Disposed))
168168
{
169-
_clusterEventsLogger.LogDebug("Disposing");
169+
_clusterEventsLogger.Logger?.LogDebug(_clusterId, "Disposing");
170170

171171
#pragma warning disable CS0618 // Type or member is obsolete
172172
var connectionModeSwitch = _description.ConnectionModeSwitch;
@@ -188,7 +188,7 @@ protected virtual void Dispose(bool disposing)
188188
_rapidHeartbeatTimer.Dispose();
189189
_cryptClient?.Dispose();
190190

191-
_clusterEventsLogger.LogDebug("Disposed");
191+
_clusterEventsLogger.Logger?.LogDebug(_clusterId, "Disposed");
192192
}
193193
}
194194

@@ -224,13 +224,17 @@ public virtual void Initialize()
224224
ThrowIfDisposed();
225225
if (_state.TryChange(State.Initial, State.Open))
226226
{
227-
_clusterEventsLogger.LogDebug("Initialized");
227+
_clusterEventsLogger.Logger?.LogDebug(_clusterId, "Initialized");
228228

229229
if (_settings.CryptClientSettings != null)
230230
{
231231
_cryptClient = CryptClientCreator.CreateCryptClient(_settings.CryptClientSettings);
232232

233-
_clusterEventsLogger.LogDebug("CryptClient created. Configured shared library, version {SharedLibraryVersion}.", _cryptClient.CryptSharedLibraryVersion ?? "None");
233+
_clusterEventsLogger.Logger?.LogDebug(
234+
StructuredLogsTemplates.ClusterId_Message_SharedLibraryVersion,
235+
_clusterId,
236+
"CryptClient created. Configured shared library version: ",
237+
_cryptClient.CryptSharedLibraryVersion ?? "None");
234238
}
235239
}
236240
}

src/MongoDB.Driver.Core/Core/Clusters/DnsMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public DnsMonitor(IDnsMonitoringCluster cluster,
6464
_service = "_mongodb._tcp." + _lookupDomainName;
6565
_state = DnsMonitorState.Created;
6666

67-
_eventsLogger = logger.ToEventsLogger(eventSubscriber, _service);
67+
_eventsLogger = logger.ToEventsLogger(eventSubscriber);
6868
}
6969

7070
// public properties

src/MongoDB.Driver.Core/Core/Clusters/LoadBalancedCluster.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public LoadBalancedCluster(
109109
#pragma warning restore CS0618 // Type or member is obsolete
110110
null);
111111

112-
_eventsLogger = loggerFactory.CreateEventsLogger<LogCategories.Cluster>(eventSubscriber, _clusterId);
112+
_eventsLogger = loggerFactory.CreateEventsLogger<LogCategories.Cluster>(eventSubscriber);
113113
}
114114

115115
public ClusterId ClusterId => _clusterId;

src/MongoDB.Driver.Core/Core/Configuration/ClusterBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private IServerMonitorFactory CreateServerMonitorFactory()
319319
serverMonitorStreamFactory,
320320
new EventAggregator(),
321321
_clusterSettings.ServerApi,
322-
_loggerFactory);
322+
loggerFactory: null);
323323

324324
return new ServerMonitorFactory(
325325
serverMonitorSettings,

src/MongoDB.Driver.Core/Core/ConnectionPools/ExclusiveConnectionPool.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public ExclusiveConnectionPool(
6565
_connectionExceptionHandler = Ensure.IsNotNull(connectionExceptionHandler, nameof(connectionExceptionHandler));
6666
Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));
6767

68-
_eventsLogger = logger.ToEventsLogger(eventSubscriber, serverId);
68+
_eventsLogger = logger.ToEventsLogger(eventSubscriber);
6969

7070
_maintenanceHelper = new MaintenanceHelper(this, _settings.MaintenanceInterval);
7171
_poolState = new PoolState(EndPointHelper.ToString(_endPoint));
@@ -210,8 +210,8 @@ public void Initialize()
210210
{
211211
if (_poolState.TransitionState(State.Paused))
212212
{
213-
_eventsLogger.LogAndPublish(new ConnectionPoolOpeningEvent(_serverId, _settings));
214-
_eventsLogger.LogAndPublish(new ConnectionPoolOpenedEvent(_serverId, _settings));
213+
_eventsLogger.LogAndPublish(new ConnectionPoolOpeningEvent(_serverId, _settings), _connectionFactory.ConnectionSettings);
214+
_eventsLogger.LogAndPublish(new ConnectionPoolOpenedEvent(_serverId, _settings), _connectionFactory.ConnectionSettings);
215215
}
216216
}
217217
}

src/MongoDB.Driver.Core/Core/Connections/BinaryConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public BinaryConnection(ServerId serverId,
8585
_state = new InterlockedInt32(State.Initial);
8686

8787
_compressorSource = new CompressorSource(settings.Compressors);
88-
_eventsLogger = loggerFactory.CreateEventsLogger<LogCategories.Connection>(eventSubscriber, ConnectionId);
89-
_commandEventHelper = new CommandEventHelper(loggerFactory.CreateEventsLogger<LogCategories.Command>(eventSubscriber, ConnectionId));
88+
_eventsLogger = loggerFactory.CreateEventsLogger<LogCategories.Connection>(eventSubscriber);
89+
_commandEventHelper = new CommandEventHelper(loggerFactory.CreateEventsLogger<LogCategories.Command>(eventSubscriber));
9090
}
9191

9292
// properties

src/MongoDB.Driver.Core/Core/Connections/BinaryConnectionFactory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public BinaryConnectionFactory(
4949
_loggerFactory = loggerFactory;
5050
}
5151

52+
// properties
53+
public ConnectionSettings ConnectionSettings => _settings;
54+
5255
// methods
5356
public IConnection CreateConnection(ServerId serverId, EndPoint endPoint)
5457
{

src/MongoDB.Driver.Core/Core/Connections/IConnectionFactory.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@
1313
* limitations under the License.
1414
*/
1515

16-
using System;
17-
using System.Collections.Generic;
18-
using System.Linq;
1916
using System.Net;
20-
using System.Text;
21-
using System.Threading;
22-
using System.Threading.Tasks;
17+
using MongoDB.Driver.Core.Configuration;
2318
using MongoDB.Driver.Core.Servers;
2419

2520
namespace MongoDB.Driver.Core.Connections
@@ -29,6 +24,12 @@ namespace MongoDB.Driver.Core.Connections
2924
/// </summary>
3025
public interface IConnectionFactory
3126
{
27+
// properties
28+
/// <summary>
29+
/// Gets the connection settings.
30+
/// </summary>
31+
ConnectionSettings ConnectionSettings { get; }
32+
3233
// methods
3334
/// <summary>
3435
/// Creates the connection.

src/MongoDB.Driver.Core/Core/Events/ClusterAddedServerEvent.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace MongoDB.Driver.Core.Events
2222
/// <summary>
2323
/// Occurs after a server is added to the cluster.
2424
/// </summary>
25-
public struct ClusterAddedServerEvent
25+
public struct ClusterAddedServerEvent : IEvent
2626
{
2727
private readonly TimeSpan _duration;
2828
private readonly ServerId _serverId;
@@ -71,5 +71,8 @@ public DateTime Timestamp
7171
{
7272
get { return _timestamp; }
7373
}
74+
75+
// explicit interface implementations
76+
EventType IEvent.Type => EventType.ClusterAddedServer;
7477
}
7578
}

src/MongoDB.Driver.Core/Core/Events/ClusterAddingServerEvent.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace MongoDB.Driver.Core.Events
2222
/// <summary>
2323
/// Occurs before a server is added to the cluster.
2424
/// </summary>
25-
public struct ClusterAddingServerEvent
25+
public struct ClusterAddingServerEvent : IEvent
2626
{
2727
private readonly ClusterId _clusterId;
2828
private readonly EndPoint _endPoint;
@@ -63,5 +63,8 @@ public DateTime Timestamp
6363
{
6464
get { return _timestamp; }
6565
}
66+
67+
// explicit interface implementations
68+
EventType IEvent.Type => EventType.ClusterAddingServer;
6669
}
6770
}

0 commit comments

Comments
 (0)