Skip to content

Commit 8d79daa

Browse files
authored
Merge pull request #186099 from Venkat1340/Users/Venkat1340/Dotnetv3performance
.NET V3 Performance: Add DefaultTraceListener note
2 parents df3e0d8 + 4d0be67 commit 8d79daa

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

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

Lines changed: 41 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,46 @@ 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+
## <a id="logging-and-tracing"></a> Logging and tracing
65+
66+
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.
67+
68+
Latest SDK versions (greater than 3.23.0) automatically remove it when they detect it, with older versions, you can remove it by:
69+
70+
# [.NET 6 / .NET Core](#tab/trace-net-core)
71+
72+
```csharp
73+
if (!Debugger.IsAttached)
74+
{
75+
Type defaultTrace = Type.GetType("Microsoft.Azure.Cosmos.Core.Trace.DefaultTrace,Microsoft.Azure.Cosmos.Direct");
76+
TraceSource traceSource = (TraceSource)defaultTrace.GetProperty("TraceSource").GetValue(null);
77+
traceSource.Listeners.Remove("Default");
78+
// Add your own trace listeners
79+
}
80+
```
81+
82+
# [.NET Framework](#tab/trace-net-fx)
83+
84+
Edit your `app.config` or `web.config` files:
85+
86+
```xml
87+
<configuration>
88+
<system.diagnostics>
89+
<sources>
90+
<source name="DocDBTrace" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >
91+
<listeners>
92+
<remove name="Default" />
93+
<!--Add your own trace listeners-->
94+
<add name="myListener" ... />
95+
</listeners>
96+
</source>
97+
</sources>
98+
</system.diagnostics>
99+
<configuration>
100+
```
101+
102+
---
103+
64104
## Networking
65105
<a id="direct-connection"></a>
66106

0 commit comments

Comments
 (0)