C# 当参数超过2时,日志文件中不显示命名空间/类/方法
我有一个WCF服务应用程序,在其Web.config中,我定义了以下log4net配置:C# 当参数超过2时,日志文件中不显示命名空间/类/方法,c#,wcf,logging,log4net,log4net-configuration,C#,Wcf,Logging,Log4net,Log4net Configuration,我有一个WCF服务应用程序,在其Web.config中,我定义了以下log4net配置: <log4net> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="F:\InternalAPIServer\logs\InternalAPIServer.log"/> <lockingM
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="F:\InternalAPIServer\logs\InternalAPIServer.log"/>
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="2" />
<maximumFileSize value="1MB" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] [%-5p] %C.%M - %m%n"/>
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
日志在日志文件中显示正常:
2017-02-14 17:12:01,056 [12] [INFO ] InternalAPIServer.Connection.ValidateServerCertficate - Server certificate validity dates: [31/5/2016 8:00:00 AM - 7/6/2017 8:00:00 PM].
但当我用三个参数调用记录器时:
Log.InfoFormat("Server certificate validity dates: [{0} - {1}].", ServerCertificate.GetEffectiveDateString(), ServerCertificate.GetExpirationDateString());
Log.InfoFormat("Server certificate issuer: [{0}], validity dates: [{1} - {2}].", ServerCertificate.Issuer, ServerCertificate.GetEffectiveDateString(), ServerCertificate.GetExpirationDateString());
日志不再正常,因为命名空间、类和方法名称变为“?”:
为什么会这样?当记录器的参数数超过两个时,如何防止命名空间、类和方法名被抑制
提前感谢。我不太清楚您应该在Log4Net中使用的参数,但是您的错误一定是从中发生的,因为您应该传递一个普通字符串 您可以使用
String.Format()
来实现这一点
因此,您应该能够交替使用
Log.InfoFormat(String.Format("{0} {1}", string1, string2));
string message = String.Format("Server certificate issuer: [{0}], validity dates: [{1} - {2}].",
ServerCertificate.Issuer,
ServerCertificate.GetEffectiveDateString(),
ServerCertificate.GetExpirationDateString())
Log.InfoFormat(message);
Log.InfoFormat(String.Format("{0} {1}", string1, string2));