我的所有连接都是从我的代码中设置的,而不是使用我的配置文件.如何在从代码构建的连接上设置WCF跟踪.我尝试添加跟踪到配置文件,如解释在这里,但是无论如何不会产生日志.
我需要知道如何使用配置文件使其工作在代码中设置的连接,或者如果有人有任何信息,如何在代码中手动配置它.谢谢!
编辑:添加更多信息:
该应用程序是一个C#Console应用程序,我的绑定声明为:
private Binding getBinding()
{
NetTcpBinding tcp = new NetTcpBinding();
tcp.ReaderQuotas.MaxArrayLength = 65535;
tcp.TransferMode = TransferMode.Streamed;
tcp.ReaderQuotas.MaxArrayLength = int.MaxValue;
tcp.ReaderQuotas.MaxDepth = int.MaxValue;
tcp.ReaderQuotas.MaxStringContentLength = int.MaxValue;
tcp.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
tcp.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
tcp.MaxReceivedMessageSize = int.MaxValue;
return tcp;
}
Run Code Online (Sandbox Code Playgroud)
然后我使用通用函数向我的应用添加服务:
private List<ServiceHost> m_Hosts = new List<ServiceHost>();
private static List<string> m_Services = new List<string>();
public void AddHost<T1, T2>(string uri)
where T1 : class
where T2 : class
{
m_Services.Add("net.tcp://<ipaddress>:<port>/" + uri);
m_Hosts.Add(new ServiceHost(typeof(T1)));
m_Hosts[m_Hosts.Count - 1].AddServiceEndpoint(typeof(T2), getBinding(), m_Services[m_Services.Count - 1]);
}
Run Code Online (Sandbox Code Playgroud)
显然有一些代码可以使这一切工作,但这应该给出任何相关的部分.
以下是.config启用跟踪的示例,如果您想再次尝试.确保该.config文件位于WCF服务主机的同一文件夹中.
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Warning" propagateActivity="true" >
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="myUserTraceSource" switchValue="Warning, ActivityTracing">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="TraceLog.svclog" />
</sharedListeners>
</system.diagnostics>
</configuration>
Run Code Online (Sandbox Code Playgroud)
Microsoft提供了一个服务跟踪查看器工具来读取.svclog文件.
确保保存.svclog的路径具有必要的写入权限.
| 归档时间: |
|
| 查看次数: |
5742 次 |
| 最近记录: |