Environment variable does not get read?
Posted
by sanjeev40084
on Stack Overflow
See other posts from Stack Overflow
or by sanjeev40084
Published on 2010-04-08T03:26:22Z
Indexed on
2010/04/08
3:33 UTC
Read the original article
Hit count: 522
I have a console application in Visual studio. i have log4net stuff with smtp appender in my app.config file. I have set environment variable in my code (i.e. my email address) and trying to reference this environment variable to send email. However log4net doesn't seem to read this value when the application is run.
My log4net:
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="smtp" type="log4net.Appender.SmtpAppender">
<param name="to" value="${EmailAddress}" />
<param name="from" value="[email protected]" />
<param name="subject" value="testing app" />
<param name="smtpHost" value="<smtp host name>" />
<param name="bufferSize" value="1" />
<param name="lossy" value="false" />
<param name="Threshold" value="ERROR"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d{ISO8601} [%t] [%-5p] %c - %m%n" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default priority -->
<root>
<priority value="ALL" />
<appender-ref ref="smtp" />
</root>
</log4net>
</Configuration>
In my console app, i have set environment variable something like this:
Environment.SetEnvironmentVariable("EmailAddress", "[email protected]", EnvironmentVariableTarget.Process);
Does anyone know how can i make it work? Thanks.
© Stack Overflow or respective owner