1

I'm developing a small open source library which is also available on Nuget with no dependencies. Now I want to use NLog just for debugging purposes in "Debug Mode" but I don't want it to be a dependency when I release new versions on Nuget. What is the best way to do it if this is a reasonable approach at all.

thanks

hrzafer
  • 1,123
  • 1
  • 15
  • 35
  • 2
    Use [#if DEBUG or the Conditional(“DEBUG”) attribute](http://stackoverflow.com/questions/3788605/if-debug-vs-conditionaldebug) to stop the code being included in release mode, and a [conditional project reference](https://whathecode.wordpress.com/2012/10/07/conditional-project-or-library-reference-in-visual-studio/) to remove the NLog dependency in Release mode. – stuartd Dec 21 '15 at 15:35
  • I don't think you're able to add or remove project dependencies based on configuration (Release vs Debug). You can use the solution provided above as a starting point. – Alex Dec 21 '15 at 15:39

1 Answers1

1

You can use

Logger.ConditionalTrace("entering method {0}", methodname);

etc. Those will be removed in a non-debug build. . See NLog 4.0 release post. Then you can safely remove the dependency in your NuGet package.

Julian
  • 33,915
  • 22
  • 119
  • 174