ODP.NET Tracing — The Basics

Alex Keh
Oracle Developers
Published in
3 min readMay 26, 2020

I previously wrote about some new features in ODP.NET tracing. Then, I realized not everyone necessarily knows how to enable and configure ODP.NET tracing in general. For this blog post, I’ll teach some of the basics and share some code and configuration that you can cut and paste into your .NET app to easily generate an ODP.NET trace when you need it.

The Basics

ODP.NET tracing has two common settings you will always use:

  • TraceFileLocation— trace file directory location
  • TraceLevel — tracing level

TraceFileLocation is not required to be set as it will use a default operating system temporary directory location. However, most people set a value to make the trace file(s) easier to find.

By default, TraceLevel has a value of zero, which disables tracing. This is what you want most of the time since tracing adds overhead to your app and will slow down performance. When you encounter a problem you want to learn more about or need Oracle to diagnose and fix, then enable tracing by setting a value to TraceLevel. ODP.NET has numerous tracing levels to trace different types of operations the provider is performing externally and internally.

In general, you can set the trace level to trace all ODP.NET operations. That’s the the most likely to capture enough info for debugging. For managed ODP.NET and ODP.NET Core, that level is 7. For unmanaged ODP.NET, that level is 127.

Give Me Some Config or Config (to Cut and Paste)

You can set these values in a number of locations. The easiest places are in the .NET config file or in the code. Use the former if you don’t want to rebuild. Use the latter if you don’t use a .NET config file. Here’s a sample configuration for managed ODP.NET:

<oracle.manageddataaccess.client>
<version number="*">
<settings>
<setting name=”TraceLevel” value=”7" />
<setting name=”TraceFileLocation” value=”D:\traces\”/>
</settings>
</version>
</oracle.manageddataaccess.client>

Make sure to add this sample within the<configuration> section of the .NET config file. Set the trace file location directory location as needed.

Unmanaged ODP.NET use the same settings, but are located in a different subsection <oracle.unmanageddataaccess.client>. For example,

<oracle.unmanageddataaccess.client>
<version number="*">
<settings>
<setting name=”TraceLevel” value=”127" />
<setting name=”TraceFileLocation” value=”D:\traces\”/>
</settings>
</version>
</oracle.unmanageddataaccess.client>

Once these modifications are saved, restart the app. The trace file will be created and populated once ODP.NET APIs are invoked.

ODP.NET Core doesn’t use .NET configuration files currently. A future release will provide a configuration file for trace settings.

ODP.NET Core primarily uses code for configuration. The ODP.NET OracleConfiguration class contains the trace level and trace file location settings and can be set in C# using the following sample:

OracleConfiguration.TraceFileLocation = @"D:\traces";
OracleConfiguration.TraceLevel = 7;

If you would like to trace all ODP.NET calls, be sure to add this code snippet prior to your app calling any other ODP.NET APIs. If your ODP.NET version supports dynamic tracing, place these calls ahead of the problematic code region.

In ODAC 19c and higher, these OracleConfiguration trace settings are available in managed and unmanaged ODP.NET as well.

Conclusion

I hope you learned a bit about how ODP.NET tracing works. You can copy and paste these code and config snippets into your own apps when you need to enable ODP.NET tracing.

--

--

Alex Keh
Oracle Developers

Alex Keh is a senior principal product manager at Oracle focusing on data access and database integration with .NET, Windows, and the cloud.