简体   繁体   English

将app.config值设置为Environment.UserName

[英]Set app.config value to Environment.UserName

I have an Exception Handler that email our Help Desk software whenever there is an error. 我有一个异常处理程序,每当发生错误时,该异常处理程序就会通过电子邮件将我们的帮助台软件发送给我们。 All properties for the Mailer are handled in app.config. Mailer的所有属性都在app.config中处理。 One of which looks like this --> <add key="from" value="MATRIX@Exception.Handler"/> 其中之一看起来像这样-> <add key="from" value="MATRIX@Exception.Handler"/>

Is there a way to have the value set to Environment.Username + '@ourcompany.org . 有没有一种方法可以将值设置为Environment.Username + '@ourcompany.org

As a side note this is an internal app only. 附带说明,这仅是内部应用程序。

Use the Macro pattern. 使用宏模式。 Set the value to be [User]@Exception.Handler, then wrap it in a helper method. 将值设置为[User] @ Exception.Handler,然后将其包装在辅助方法中。 Add String.Replace("[User]", Environment.Username) in the helper, and you are good to go. 在帮助器中添加String.Replace(“ [User]”,Environment.Username),一切顺利。

Always wrap configuration values in helper method. 始终将配置值包装在辅助方法中。 This allows you to convert from string to other type, check for invalid values, substitute defaults, etc. Configuration files frequently are incorrect or mangled causing difficult-to-diagnose runtime errors. 这使您可以从字符串转换为其他类型,检查无效值,替换默认值等。配置文件经常不正确或损坏,导致难以诊断的运行时错误。

This is not possible. 这是不可能的。
You will need to modify the code that reads the value. 您将需要修改读取该值的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM