2

I use NLog for logging and now I'm trying to also use it for my SharePoint solution.
How do I instruct WSPBuilder to include NLog.config in WSP and place it in the same folder as solution dll?

EDIT:

Okay, another option is to put it as Web.nlog in SharePoint 80 directory.
Do I need a separate feature for this? What should I write in elements.xml?

Dan Abramov
  • 264,556
  • 84
  • 409
  • 511

3 Answers3

3

I don't think this can't be done - I assume for security reasons.

DLLs can only be deployed to GAC (signed assemblies only) or to the bin directory of the web application (deployed via the solution manifest, along with any required CAS policies).

If you want extra files alongside the assembly in the bin directory, you'll need to copy them manually.

James Love
  • 1,025
  • 9
  • 16
  • Thank you for your response. Please, can you give your opinion on edit? – Dan Abramov Mar 04 '11 at 20:38
  • Provisioned files via the elements.xml in a feature can only be placed into the 12 hive (`Program files \ common files \ microsoft shared \ web server extensions \ 12 \ template` directory). They can be placed either into any sub folder of the Layouts directory (they are then available to every site in the farm) or into any document library in the site in which Feature is activated. – James Love Mar 04 '11 at 20:41
  • 1
    In short, you might have to just simply add a manual deployment step to your solution to copy this file somewhere usable. Don't be disheartened at this - I've had to do manual steps sometimes and yes, it feels dirty as hell, but sometimes it's the only way. – James Love Mar 04 '11 at 20:43
  • Yay for manual step, seems like an easier solution to support than some config-changing code. – Dan Abramov Mar 04 '11 at 23:47
3

Does NLog.config need to be a separate file, or can the settings be integrated into the web.config file? If you can integrate the settings into the web.config file, you can add a feature receiver and write the necessary settings during the FeatureActivated or FeatureInstalling event to web.config using SPWebConfigModifications (just google for it). You should also make sure to remove the settings in FeatureDeactivating or FeatureUninstalled event.

Robert Seso
  • 201
  • 1
  • 3
  • Yes, NLog config can be placed in `web.config` as well. However I mark the other answer as correct because doing so manually looks like more easily maintainable solution in the long run. Thanks for your effort! – Dan Abramov Mar 04 '11 at 23:48
  • Not if you have a farm with more than one server in it, in which case you have to manually keep web.config files in sync on all servers. Also, if you ever add a new server to the farm, you will have to remember to add your settings to its web.config manually, whereas if you did it through SPWebConfigModifications it would have been done automatically. So doing it by hand is the worst possible way to do it, actually. – Robert Seso Mar 05 '11 at 07:55
  • Instead of changing `web.config`s, I went for placing special `web.nlog` file into same directory with config, as it works with NLog well. Manually changing `web.config` is a bad idea, however placing an additional file is something simple. – Dan Abramov Mar 09 '11 at 02:02
0

You should also take a look here : http://msdn.microsoft.com/en-us/library/ee413935.aspx

I would also ask these questions :

  • Is the configuration the same for all the farm ? Only one web application ?
  • Can you programmaticaly specify NLog configuration ?

Depending on your answers, I will suggest one or more solutions. The disadvantages with the web.config are

  • Configuration is deployed on all SharePoint servers (the feature take care of that, but you have to keep that in mind in case of inconsistant behavior)
  • If you want to modify settings there is no easy way
  • Each time you modify settings, it will recycle application pool.
Sylvain Reverdy
  • 2,468
  • 3
  • 16
  • 14
  • There is just one server with one web application in question and no plans for expansion so it's pretty straightforward. Unfortunately loading XML dynamically is somewhat badly documented in NLog. I won't store the settings in web.config / web.nlog — they will just include hardcoded reference to one file in SharePoint CONFIG directory which can be modified and automatically reloaded at runtime. I just need to give NLog initial place to look. – Dan Abramov Mar 05 '11 at 00:19
  • I see. Storing configuration in 12 Hive is straightforward but not easy to update (without updating WSP or manually updating it). But with one server / application, it should be OK :) – Sylvain Reverdy Mar 05 '11 at 00:37