环境变量没有被读取?
我在 Visual Studio 中有一个控制台应用程序。我的 app.config 文件中有带有 smtp 附加程序的 log4net 内容。我在代码中设置了环境变量(即我的电子邮件地址)并尝试引用此环境变量来发送电子邮件。然而,当应用程序运行时,log4net 似乎没有读取该值。
我的 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>
<root>
<priority value="ALL" />
<appender-ref ref="smtp" />
</root>
</log4net>
</Configuration>
在我的控制台应用程序中,我设置了这样的环境变量:
Environment.SetEnvironmentVariable("EmailAddress", "[email protected]", EnvironmentVariableTarget.Process);
有谁知道我怎样才能使它工作? 谢谢。
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>
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到旧的发行说明 log4net 表示您使用带有货币符号和括号的环境变量。但我以前从未使用过这种风格。
我使用 百分比 样式来访问特殊文件夹它有效。使用您的自定义环境变量尝试这样。
但是,我确实要问为什么你要在环境变量中添加“收件人:”电子邮件地址?你不能使用一些更现代的东西,比如内置的 log4net Contexts?
I see an old release notes for log4net that says you use an environment variable with the money sign and brackets. But I've never used that style before.
I've used the percent style for accessing special folders and it works. Try it like this with your custom environment variable.
But, I do have to ask why you're putting a "To:" email address in an environment variable? Can't you use something a bit more modern like the built in log4net Contexts?