【发布时间】:2013-02-21 06:38:54
【问题描述】:
我有一个连接到我的 wcf 服务的客户端程序。我想将应用配置嵌入到C#代码中,直到用户无法更改甚至无法查看 app.config。
但我无法将这两个配置设置带入 C# 代码:
<system.diagnostics>
<sources>
<source propagateActivity="true" name="System.ServiceModel" switchValue="Warning">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="NewListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing" >
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="NewListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="Trace.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="NewListener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack">
<filter type="" />
</add>
</sharedListeners>
</system.diagnostics>
还有
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true" >
<proxy autoDetect="True" usesystemdefault="True"/>
</defaultProxy>
</system.net>
我添加了一些这样的代码
System.Diagnostics.XmlWriterTraceListener xmlt = new System.Diagnostics.XmlWriterTraceListener("Trace.svclog", "myListener");
System.Diagnostics.Trace.Listeners.Add(xmlt):
但是没有用。当您在 app.config 文件中设置跟踪侦听器时,应用程序将自动记录异常、警告等发生我自己。
关于默认代理,我找到了一些类,但我在类中找不到这些设置。
问题:
1-我想将这些设置带到 C# 代码中。(我希望 C# 结果与 app.config 结果完全相同)
2- app.config 比 C# 代码强吗?我可以在 c# 类中找到所有 app.config 设置吗?
【问题讨论】:
-
here 有一个绝妙的解决方案。
标签: c# wcf configuration wcf-client wcf-configuration