oracle 启用 ODP.Net 日志记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5915343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:36:52  来源:igfitidea点击:

Enable ODP.Net logging

c#oracleado.nettraceodp.net

提问by Viren Jhala

Can anyone help me with enabling ODP.Net logging on a Windows XP machine? I googled and found following link but it did not work for me.

谁能帮我在 Windows XP 机器上启用 ODP.Net 日志记录?我用谷歌搜索并找到了以下链接,但它对我不起作用。

http://download.oracle.com/docs/html/E10927_01/featConfig.htm

http://download.oracle.com/docs/html/E10927_01/featConfig.htm

I set the "TraceLevel" setting to "63" in registry but it did not help

我在注册表中将“TraceLevel”设置为“63”,但没有帮助

Basically I want to capture all the database call happening from my C# code through the log.

基本上我想通过日志捕获从我的 C# 代码发生的所有数据库调用。

I wish there was a tool like "SQL Profiler" for Oracle.

我希望有一个像 Oracle 的“SQL Profiler”这样的工具。

回答by tsells

I had the same issues on certain machines when troubleshooting some issues with Oracle Support. I found that changing the path to the output file a couple of times and multiple restarts finally forced the ODP client to start logging. Make sure that the output file is to a directory that your calling application identity has access to.

在对 Oracle Support 的一些问题进行故障排除时,我在某些机器上遇到了同样的问题。我发现多次更改输出文件的路径并多次重启最终迫使 ODP 客户端开始记录。确保输出文件位于您的调用应用程序身份可以访问的目录中。

Check the following things in the registry keys. Here is an example from my machine for .net4 and 11.2.

检查注册表项中的以下内容。这是我的机器上的 .net4 和 11.2 的示例。

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE\ODP.NET\4.112.2.0

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE\ODP.NET\4.112.2.0

  • 32 or 64 bit (correct node)
  • Change the Trace Level to 8 (or 64 I think for complete logging)
  • Change the Trace Option = 1
  • Set a valid TraceFileName
  • 32 或 64 位(正确的节点)
  • 将跟踪级别更改为 8(或 64,我认为是完整的日志记录)
  • 更改跟踪选项 = 1
  • 设置有效的 TraceFileName

回答by Christian Shay

Note that the trace will default to go in the root of the C drive. For Windows 7 and later, this requires administrator privilege or it will just fail silently. So either make sure your app is running as administrator or that you change the path of the file.

请注意,跟踪将默认进入 C 驱动器的根目录。对于 Windows 7 及更高版本,这需要管理员权限,否则它只会静默失败。因此,要么确保您的应用程序以管理员身份运行,要么您更改文件的路径。

Also note, that if you want to trace ODP.NET fully managed, you need to put the settings inside the app or web config file, not the registry, AND the settings for TraceLevel are different (1 through 7).

另请注意,如果您想跟踪 ODP.NET 完全托管,您需要将设置放在应用程序或 Web 配置文件中,而不是注册表中,并且 TraceLevel 的设置不同(1 到 7)。

And finally, when tracing unmanaged ODP.NET remember that there is a separate WOW registry node for 32 bit Windows. If your app is 32 bit, don't accidentally set it under the 64 bit portion of the registry.

最后,在跟踪非托管 ODP.NET 时请记住,32 位 Windows 有一个单独的 WOW 注册表节点。如果您的应用程序是 32 位,请不要意外将其设置在注册表的 64 位部分下。

回答by Buthrakaur

You can also use AOP-based approach - generate proxy using library like Castle Dynamic Proxy, intercept the calls you're interested in and log the arguments like SQL and parameters. This is more powerful method in my opinion although it can somehow affect performance. See this Gist for sample implementation: https://gist.github.com/Buthrakaur/b1124c08f8521f39f8fd

您还可以使用基于 AOP 的方法 - 使用 Castle Dynamic Proxy 等库生成代理,拦截您感兴趣的调用并记录 SQL 和参数等参数。在我看来,这是更强大的方法,尽管它会以某种方式影响性能。有关示例实现,请参阅此要点:https: //gist.github.com/Buthrakaur/b1124c08f8521f39f8fd