0

I would like to create a separate log file for a C# com server dll I load into Excel. However, when I set up my logger I need to tell it where the assembly.dll.config file is. This config file is located in C:\Program Files (x86)\My Company Name but I don't know how to get this path in a dynamic way at runtime and I don't want to hard code it for obvious reasons.

I tried to use:

AppDomain.CurrentDomain.BaseDirectory + "assembly.dll.config" but this just gives me Excel's install directory:

C:\Program Files (x86)\Microsoft Office\Office14\assembly.dll.config

Is there some way I can get the path of the dll's config file at runtime?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Pat Mustard
  • 1,852
  • 9
  • 31
  • 58
  • 1
    The Assembly type has the following static methods: GetCallingAssembly, GetEntryAssembly, GetExecutingAssembly. Is it this what you are looking for? –  Nov 15 '13 at 02:37
  • Yes, just found it here: http://stackoverflow.com/questions/4764680/how-to-get-the-location-of-the-dll-currently-executing `string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);` Thanks! – Pat Mustard Nov 15 '13 at 02:39
  • Side note: assemblies normally don't have own ".config" files, so what you are trying to do is unusual and likely to be overlooked by anyone else using your system in the future. – Alexei Levenkov Nov 15 '13 at 02:40
  • @Alexei: Generally not true. There are quite a few software out there that allow installation of plug-ins/extensions in form of DLLs. Those DLLs have their own config files. But i don't know what the OP is shooting for... :) –  Nov 15 '13 at 02:42
  • The reason I want the dll to have it's own config file is that it's an in-process com server that I send data to via a socket from an add-in. So, for trouble shooting purposes, I want the add-in to have a log and also the com server to have a log just to make it easier to track down issues in this client-server setup. I'm not sure if this is best practice but it does limit log entries to one "subject" per log file (i.e. add-in or com server), which to me makes sense... :) – Pat Mustard Nov 15 '13 at 08:47

0 Answers0