等效于PCL库中的System.Diagnostics.Trace [英] Equivalent for System.Diagnostics.Trace in PCL library

查看:47
本文介绍了等效于PCL库中的System.Diagnostics.Trace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很惊讶得知System.Diagnostics.Trace没有包含在可移植类库配置文件中.虽然可以使用System.Diagnostics.Debug.

I was surprised to learn that System.Diagnostics.Trace is not included in the Portable Class Library profiles. System.Diagnostics.Debug is available though.

我要将库移植到PCL,通常使用Trace语句为使用者提供其他故障排除.出于性能原因,我希望对程序集进行优化,以便仅在NuGet软件包中发布该程序集的发行版.

I'm porting a library to a PCL and have typically used Trace statements to provide additional troubleshooting to consumers. For performance reasons, I want the assembly optimized so I only ship Release versions of the assembly in my NuGet package.

我的理解是System.Diagnostics.Debug的方法是有条件编译的,因此仅在程序集包含DEBUG指令时才有用.

My understanding is that the methods for System.Diagnostics.Debug are conditionally compiled and therefore only useful when the assembly includes the DEBUG directive.

如果我更改代码以使用System.Diagnostics.Debug,然后在Release中进行编译,则该方法无用-PCL中是否有System.Diagnostics.Trace的替代方案,或者我必须在Release中包含DEBUG指令建造?还是我应该考虑另一种方法?

If I change my code to use System.Diagnostics.Debug and then compile in Release the approach is useless -- is there an alternative to System.Diagnostics.Trace in PCL or do I have to include the DEBUG directive in my Release build? Or is there another approach I should be considering?

推荐答案

您可以在单个C#文件中指定条件编译指令.因此,您可以围绕Debug.Trace创建自己的包装器,并仅为该代码文件定义DEBUG指令,这将使您可以从发行版DLL中调用Debug.Trace.

You can specify conditional compilation directives in an individual C# file. So you can create your own wrapper around Debug.Trace, and define the DEBUG directive just for that code file, which will let you call Debug.Trace from a release DLL.

这篇关于等效于PCL库中的System.Diagnostics.Trace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆