Skip to content

Commit 56c1530

Browse files
committed
.NET V3 Performance: Add DefaultTraceListener note
1 parent 72b50c5 commit 56c1530

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

articles/cosmos-db/sql/performance-tips-dotnet-sdk-v3-sql.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: j82w
55
ms.service: cosmos-db
66
ms.subservice: cosmosdb-sql
77
ms.topic: how-to
8-
ms.date: 07/08/2021
8+
ms.date: 01/25/2022
99
ms.author: jawilley
1010
ms.devlang: csharp
1111
ms.custom: devx-track-dotnet, contperf-fy21q2
@@ -61,6 +61,47 @@ If you're testing at high throughput levels, or at rates that are greater than 5
6161
> [!NOTE]
6262
> High CPU usage can cause increased latency and request timeout exceptions.
6363
64+
## Logging and tracing
65+
<a id="logging-and-tracing"></a>
66+
67+
Some environments have the [.NET DefaultTraceListener](/dotnet/api/system.diagnostics.defaulttracelistener) enabled. The DefaultTraceListener poses performance issues on production environments causing high CPU and I/O bottlenecks. Check and make sure that the DefaultTraceListener is disabled for your application by removing it from the [TraceListeners](/dotnet/framework/debug-trace-profile/how-to-create-and-initialize-trace-listeners) on production environments.
68+
69+
Latest SDK versions (greater than 3.23.0) automatically remove it when they detect it, with older versions, you can remove it by:
70+
71+
# [.NET 6 / .NET Core](#tab/trace-net-core)
72+
73+
```csharp
74+
if (!Debugger.IsAttached)
75+
{
76+
Type defaultTrace = Type.GetType("Microsoft.Azure.Cosmos.Core.Trace.DefaultTrace,Microsoft.Azure.Cosmos.Direct");
77+
TraceSource traceSource = (TraceSource)defaultTrace.GetProperty("TraceSource").GetValue(null);
78+
traceSource.Listeners.Remove("Default");
79+
// Add your own trace listeners
80+
}
81+
```
82+
83+
# [.NET Framework](#tab/trace-net-fx)
84+
85+
Edit your `app.config` or `web.config` files:
86+
87+
```xml
88+
<configuration>
89+
<system.diagnostics>
90+
<sources>
91+
<source name="DocDBTrace" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >
92+
<listeners>
93+
<remove name="Default" />
94+
<!--Add your own trace listeners-->
95+
<add name="myListener" ... />
96+
</listeners>
97+
</source>
98+
</sources>
99+
</system.diagnostics>
100+
<configuration>
101+
```
102+
103+
---
104+
64105
## Networking
65106
<a id="direct-connection"></a>
66107

0 commit comments

Comments
 (0)