最近做的一个小程序(Windows Console),不是很大,就把错误信息写在exe.config里,但是在程序里读取config时发现,从config里取出来的回车符号("n)没有被正确解析,调试的时候才发现, “"n”都被自动换成了“"n"n”。也不知道为什么…. 0(>_<)0

      后来把“"n”换成”&#10;”才能正常解析。(感谢前辈的悉心指导)

代码实现

Config中的字段

<add key="0004" value="The Message Just For A Test&#10;No.{0}&#10;{1}"/>

CS文件中的代码

                            //存入应用程序log

            string LOG_NAME = "Application";

            string source = "TestSource1";

            string msg = string.Empty;

            msg = String.Format(

                        ConfigurationManager.AppSettings["0004"],

                        "0",

                        "1",

                        );

            int myEventID = 20;

            short myCategory = 10;

            if (!EventLog.SourceExists(source))

            {

                EventLog.CreateEventSource(source, LOG_NAME);

            }

            EventLog.WriteEntry(source, msg, EventLogEntryType.Information, myEventID, myCategory);

相关文章:

  • 2021-08-25
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2021-11-11
  • 2021-11-11
  • 2022-01-09
猜你喜欢
  • 2021-11-11
  • 2022-01-24
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案