【发布时间】:2019-04-21 17:18:10
【问题描述】:
我有一个单独的项目用于登录我的 web api 解决方案。在日志记录项目中,我使用的是 log4net dll。一切正常。
看起来我还必须在我的 web api 项目中添加 log4net dll,这是我的应用程序的入口点。
1)为什么我需要在我的 web api 项目中添加 log4net dll?
2) 有没有办法在 web api 项目中不添加 log4net 来完成这项工作?我喜欢在不同的应用程序中使用我的 logger peoject,并且不想在多个项目中使用 log4net。
public class Logger : ILogger
{
private static readonly ILog LoggerObj = LogManager.GetLogger("ErrorLog");
public Logger()
{
XmlConfigurator.Configure();
}
}
Global.asax
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
UnityConfig.RegisterComponents();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
// Initialize log4net.
//log4net.Config.XmlConfigurator.Configure();
// Initialize log4net.
var logger = new Logger();
}
【问题讨论】:
标签: c# asp.net-web-api logging log4net