Web 服务中的 log4net 问题
我们在 UI 层中成功使用了 log4net,但是当我们在 Webservice 层中测试时,它不起作用。
这是 UI 层中的代码:
public partial class _Default : System.Web.UI.Page
{
ILog logger = log4net.LogManager.GetLogger(typeof(_Default));
protected void Page_Load(object sender, EventArgs e)
{
ServiceReference1.IService1 is1 = new ServiceReference1.Service1Client();
is1.GetData(1);
logger.Info("Hello Nine Thanks for use Log4Net,This is info message");
logger.Debug("Hello Nine Thanks for use Log4Net,This is Debug message");
logger.Error("Hello Nine Thanks for use Log4Net,This is Error message");
logger.Warn("Hello Nine Thanks for use Log4Net,This is Warn message");
logger.Fatal("Hello Nine Thanks for use Log4Net,This is Fatal message");
}
}
这是 UI 层的 web.config 设置:
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="MyloggerSite2.log"/> <!-- This is logging in app root folder -->
<param name="AppendToFile" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-2p %c [%x] - %m%n"/>
</layout>
</appender>
<root>
<level value="All"/>
<appender-ref ref="FileAppender"/>
</root>
</log4net>
这是 ServiceLayer 中的代码,尽管它大部分与上面相同,但不起作用:
public class Service1 : IService1
{
public string GetData(int value)
{
ILog logger = log4net.LogManager.GetLogger(typeof(Service1));
logger.Info("Hello Nine Thanks for use Log4Net,This is info message");
logger.Debug("Hello Nine Thanks for use Log4Net,This is Debug message");
logger.Error("Hello Nine Thanks for use Log4Net,This is Error message");
logger.Warn("Hello Nine Thanks for use Log4Net,This is Warn message");
logger.Fatal("Hello Nine Thanks for use Log4Net,This is Fatal message");
return string.Format("You entered: {0}", value);
}
}
如果您有任何问题,请告诉我建议。 谢谢, 氮
We are successfully using log4net in our UI Layer but when we are testing in Webservice layer it does not work.
Here is the code in UI Layer:
public partial class _Default : System.Web.UI.Page
{
ILog logger = log4net.LogManager.GetLogger(typeof(_Default));
protected void Page_Load(object sender, EventArgs e)
{
ServiceReference1.IService1 is1 = new ServiceReference1.Service1Client();
is1.GetData(1);
logger.Info("Hello Nine Thanks for use Log4Net,This is info message");
logger.Debug("Hello Nine Thanks for use Log4Net,This is Debug message");
logger.Error("Hello Nine Thanks for use Log4Net,This is Error message");
logger.Warn("Hello Nine Thanks for use Log4Net,This is Warn message");
logger.Fatal("Hello Nine Thanks for use Log4Net,This is Fatal message");
}
}
Here is the web.config settings for the UI Layer:
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="MyloggerSite2.log"/> <!-- This is logging in app root folder -->
<param name="AppendToFile" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-2p %c [%x] - %m%n"/>
</layout>
</appender>
<root>
<level value="All"/>
<appender-ref ref="FileAppender"/>
</root>
</log4net>
Here is the code in ServiceLayer which does not work although it it is the same as above for the most:
public class Service1 : IService1
{
public string GetData(int value)
{
ILog logger = log4net.LogManager.GetLogger(typeof(Service1));
logger.Info("Hello Nine Thanks for use Log4Net,This is info message");
logger.Debug("Hello Nine Thanks for use Log4Net,This is Debug message");
logger.Error("Hello Nine Thanks for use Log4Net,This is Error message");
logger.Warn("Hello Nine Thanks for use Log4Net,This is Warn message");
logger.Fatal("Hello Nine Thanks for use Log4Net,This is Fatal message");
return string.Format("You entered: {0}", value);
}
}
Please let me know if you have any suggestions.
Thanks,
N
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚在 AssemblyInfo.cs 中手动添加了此属性:
[程序集:log4net.Config.XmlConfigurator(Watch = true)]
它有效。
谢谢。
I have just added this attribute manually in AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
It works.
Thanks.
只需在服务项目的 Web 配置文件中添加以下程序集即可。
Just add below assembly in web config file of your service's project.
例如,您是否通过在 Web 服务中使用如下属性来配置 log4net:
Do you configure log4net for instance by having an attribute like this in your web service: