0

Is it possible to define variables inside the app.config file?

Maybe like that:

<xsl:variable name="folder">
  C:\Data\Log\
</xsl:variable>

... and use it in the app.config in this way:

<file value="$folder\ErrorLog.txt" />

I have some different folders inside my app.config and won't change every path one by one.

Christoph Brückmann
  • 1,373
  • 1
  • 23
  • 41

2 Answers2

1

You can right-click on the Project in Visual Studio, and select Properties. Then go to Settings to add settings of different data types (eg. string) there.

Also, if you're looking for a log4net-specific solution, this question/answer may help: stackoverflow.com/questions/1535736

Joe L.
  • 1,888
  • 12
  • 14
  • I think that's not what I want. I got a log4net Configuration in my app.config, it has around 300 lines and around 20 pathes with different endings (files). My wish is to define the path (C:\Data\Log\) at a central location inside the app.config file. I won't replace it one by one or by "find and replace" every time I have to change it. – Christoph Brückmann Apr 09 '12 at 14:47
  • 1
    I get it now :-). I don't think there's a way to do this within the config file alone. I've needed to do something like this before but, I would define a Folder setting, and then various File1, File2, etc. settings. Then in my C# code I would read the settings and build the actual file locations by appending Folder+File1, Folder+File2, etc. I'm not sure if that will work for your log4net situation, but otherwise will allow you do define the Folder once, and reuse that for all the other files. – Joe L. Apr 09 '12 at 14:54
  • 1
    Also, if you're looking for a log4net-specific solution, this question/answer may help: http://stackoverflow.com/questions/1535736 – Joe L. Apr 09 '12 at 15:01
  • No, that will not work for me, because i wont use code for the configuration. :-/ Everything should be defined in the app.config. But maybe the second link could be helpful. I will read it later. Thanks so far! – Christoph Brückmann Apr 09 '12 at 15:16
0

You can define LogBaseDir as an environment variable and consume it in the app.config:

<appender name="RollingFileError" type="log4net.Appender.RollingFileAppender">
  <file value="${LogBaseDir}\ErrorLog.txt" />
  <!-- ... -->
</appender>
KMoraz
  • 14,004
  • 3
  • 49
  • 82