我有一个asp.net项目,它调用我的NLog包装器类(.netframework 4.7)。要让{aspnet-request}正常工作,我必须添加一个对asp.net项目的NLog.Web引用,以及对我的NLog包装类的引用。有没有一种方法可以让{aspnet}调用工作,而不是引用asp.net项目中的NLog.Web,而只是引用我的NLog包装类?我尝试在我的NLog.config中添加扩展来添加NLog.Web程序集,但无济于事。我还尝试在包装器类中只引用NLog.Web。但是asp.net项目类抛出一个错误,指出它找不到NLog.Web。提前谢谢。
当前引用:my references
NLog包装类
using System;
using NLog;
public class MyLogger {
private Logger _logger;
public MyLogger(string name)
{
_logger = LogManager.GetLogger(name);
}
public void Info(string msg, params object[] args)
{
LogEventInfo logEvent = new LogEventInfo(LogLevel.Info, _logger.Name, null, msg, args);
_logger.Log(typeof(MyLogger), logEvent);
}
}调用NLog包装类的Asp.Net项目:
WebApplication.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
EventLog.MyLogger l = new EventLog.MyLogger("uuu");
l.Info("Test {param1} and {param2}", new { OrderId = 2, Status = "Processing" }, new { OrderId = 1, Status = "Processing" });
}
}
}这是我的NLog.config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwConfigExceptions="true"
internalLogLevel="info"
internalLogFile="${basedir}\logs\internal\nlog.log">
<extensions>
<add assembly="NLog.Web"/>
</extensions>
<!-- NLog wikipedia: https://github.com/nlog/nlog/wiki/Tutorial -->
<!-- the targets to write to -->
<targets async="true">
<!-- write logs to file -->
<target xsi:type="File" name="allfile" fileName="${basedir}\logs\events\${date:format=yyyyMMdd}-${appsetting:item=Version}-${appsetting:item=Environment}.log"
layout="${longdate}
|${uppercase:${level}}
|IP:${aspnet-request-ip}
|Identity:${windows-identity}
|Controller:${aspnet-mvc-controller}
|Action:${aspnet-mvc-action}
|Callsite:${callsite}
|Message:${message} />
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--All logs-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
</rules>
</nlog>这是我在NLog包装类中得到的错误:Error Message I get
发布于 2019-10-04 04:28:26
WebApplication项目正在引用EventLog类库,但其中一个dlls未复制到项目的输出中。这是因为,即使类库引用了此dll,除了引用之外,也没有实际调用或使用此dll,因此需要显式调用此dll,以便将其复制到项目中。
因此,我在类库内的NLog.Web.dll中添加了对随机属性的虚拟调用,现在引用类库的项目在其输出文件夹( NLog.Web.dll )中获得了bin。
Dependent DLL is not getting copied to the build output folder in Visual Studio
https://stackoverflow.com/questions/58222673
复制相似问题