简体   繁体   English

NLog不从引用的dll写入

[英]NLog not writing from referenced dll

I have a dll that I created for sending email. 我有一个为发送电子邮件而创建的dll。 I have NLog included in that project that logs to c:\\logs{logfilename.log} <--This is either an error or event log. 我在该项目中包含了NLog,该日志记录到c:\\ logs {logfilename.log} <-这是错误日志或事件日志。 When working with the project locally it works just fine and writes out to the file during testing. 在本地处理项目时,它可以很好地工作,并在测试期间写出到文件中。 When I reference the emailing dll from another project that also has NLog it is not outputting to the log files. 当我从另一个也具有NLog的项目中引用电子邮件dll时,它不会输出到日志文件。 The config from the email dll is in the bin directory of the new project that is referencing it. 来自电子邮件dll的配置位于引用它的新项目的bin目录中。 I can create logs from the new project using a trace but it didn't print the email dll entries. 我可以使用跟踪从新项目创建日志,但是它没有打印电子邮件dll条目。 Is there something special I need to do in my new project to get the email dll to write the logs? 我需要在新项目中做一些特别的事情来获取电子邮件dll来写日志吗? I've searched for an answer to this but the keywords do not produce the results I would need. 我已经找到了答案,但是关键字无法产生我需要的结果。 I'm new to NLog, please be gentle. 我是NLog的新手,请保持温柔。

NLog.config 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">
<targets>
<target xsi:type="File"
        name="default"
        layout="${longdate} - ${level:uppercase=true}: ${message}${onexception:${newline}EXCEPTION\: ${exception:format=ToString}}"
        fileName="C:\logs\default.log"
        keepFileOpen="false"
        archiveFileName="C:\logs\NTC_Utility\default.{##}.log"
        archiveNumbering="Sequence"
        archiveEvery="Day"
        maxArchiveFiles="30"
        />
<target xsi:type="File"
    name="error"
    layout="${longdate} - ${level:uppercase=true}: ${message}${onexception:${newline}EXCEPTION\: ${exception:format=ToString}}"
    fileName="C:\logs\error.log"
    keepFileOpen="false"
    archiveFileName="C:\logs\NTC_Utility\error.{##}.log"
    archiveNumbering="Sequence"
    archiveEvery="Day"
    maxArchiveFiles="90"
        />

<target xsi:type="File"
        name="emailLog"
        layout="-------------------- ${message} (${longdate}) --------------------${newline}
From: ${event-context:item=From}${newline}
To: ${event-context:item=To}${newline}
BCC: ${event-context:item=Bcc}${newline}
CC: ${event-context:item=CC}${newline}
Subject: ${event-context:item=Subject}${newline}
Body: ${event-context:item=Body}${newline}
Attachments: ${event-  context:item=Attachments}${newline}--------------------------------------------------------------------${newline}"
        fileName="C:\logs\EmailLog.log"
        keepFileOpen="false"
        archiveFileName="C:\logs\NTC_Utility\EmailLog_.{##}.log"
        archiveNumbering="Sequence"
        archiveEvery="Day"
        maxArchiveFiles="90"
        />

</targets>

<rules>
<logger name="*" writeTo="error" level="Error" final="true" />
<logger name="*" writeTo="emailLog" level="Info" final="true" />
<logger name="*" writeTo="default" minLevel="Debug" />
</rules>
</nlog>

This is my Log.cs from the compiled utility dll 这是来自编译实用程序dll的Log.cs

using NLog;
namespace NTC.Utility
{
    internal static class Log
    {
        public static Logger Instance { get; private set;}
        static Log()
        {
            LogManager.ReconfigExistingLoggers();
            Instance = LogManager.GetCurrentClassLogger();
        }
    }
}

This line calls my Logging Method after the email is sent. 发送电子邮件后,此行调用我的日志记录方法。

LogEmailSent(imperEmail);

Which calls this method... 哪个调用此方法...

    private void LogEmailSent(EmailMessage email)
    {            
        Logger logger = LogManager.GetCurrentClassLogger();
        LogEventInfo thisEvent = new LogEventInfo(LogLevel.Info, "default","Email Sent");
        thisEvent.Properties["From"] = email.From;
        thisEvent.Properties["To"] = EmailCollectionToCsv(email.ToRecipients);            
        thisEvent.Properties["Bcc"] = EmailCollectionToCsv(email.BccRecipients);
        thisEvent.Properties["CC"] = EmailCollectionToCsv(email.CcRecipients);
        thisEvent.Properties["Subject"] = email.Subject;
        thisEvent.Properties["Body"] = email.Body;
        thisEvent.Properties["Attachments"] = AttachmentCollectionToCsv(email.Attachments);
        logger.Log(thisEvent);

    }

check your nlog.config if not. 如果没有,请检查您的nlog.config。 are there any posibilities some configurations are injected within the code.. 代码中是否注入了某些配置?

http://www.codeproject.com/Articles/10631/Introduction-to-NLog http://www.codeproject.com/Articles/10631/Introduction-to-NLog

好的,所以我最终确定了记录跟踪之后发生了什么...我注意到它只显示了加载时的错误规则。...所以我将“ emaillog”规则移到了“ error”规则之上,工作完美。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM