English 中文(简体)
将 app.config 的值设置为 Environment.UserName。
原标题:Set app.config value to Environment.UserName

我有一个异常处理程序,每当出现错误时,它会向我们的帮助台软件发送电子邮件。邮件程序的所有属性都在app.config中处理。其中一个具有以下格式的属性 -> <add key="from" value="MATRIX@Exception.Handler"/>

有没有一种方法可以将值设置为 Environment.Username + @ourcompany.org

顺便提一下,这是一款仅限于内部使用的应用程序。

问题回答

使用宏模式。 将值设置为[User] @Exception.Handler,然后将其包装在辅助方法中。在帮助器中添加String.Replace(“[User]”,Environment.Username),然后就可以使用了。

始终将配置值包装在辅助方法中。这样可以将字符串转换为其他类型,检查无效值,替换默认值等。配置文件经常不正确或损坏,导致难以诊断的运行时错误。

This is not possible.
You will need to modify the code that reads the value.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签