3
<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
  </startup>
  <system.diagnostics>
    <trace autoflush="true" indentsize="1">
      <listeners>
        <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="%LOCALAPPDATA%\DBLog\application.log">          
          <filter type="System.Diagnostics.EventTypeFilter" initializeData="Verbose"/>
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

How does I solve the problem with %LOCALAPPDATA% not working in my app.config, I need to able to configure inside a xml file. Not in the code if possible. It's the

3 Answers3

2

Please try this ${LOCALAPPDATA}

Kapoor
  • 1,388
  • 11
  • 21
  • @4thex which .net verison ? – Kapoor Mar 20 '19 at 14:00
  • My comment was about using it inside system.diagnostics. It will not resolve an environment variable inside the initializeData attribute. The .NET Framework version I am using is 4.5.2. – 4thex Mar 21 '19 at 14:13
2

%LOCALAPPDATA% dosen't work in app.config

It doesn not seem to work. See related question here or here.

I suggest you the following:

  • If you wanna use the ${VARIABLE} syntax you should try log4net. There is a great tutorial on codeplex.
  • Else you have to expand your environment variables and create your trace listeners in code.
Community
  • 1
  • 1
Marschal
  • 173
  • 2
  • 11
1

Please try to modify your code to this :

initializeData="${LOCALAPPDATA}\DBLog\application.log"