log4net 2.0.8 nuget中缺少SmtpAppender吗? [英] SmtpAppender missing in log4net 2.0.8 nuget?

查看:225
本文介绍了log4net 2.0.8 nuget中缺少SmtpAppender吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为.NET Core 2.0创建了一个控制台应用程序,并安装了log4net 2.0.8 nuget

I created a console app for .NET Core 2.0 and installed a log4net 2.0.8 nuget

我想使用SmtpAppender,但它在库中不存在

I want to use the SmtpAppender but it does not exist in the library

这是我的log4net配置

This is my log4net configuration

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
   <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
    <to value="test@test.com" />
    <from value="test@test.com" />
    <subject type="log4net.Util.PatternString" value="Message logged" />
    <smtpHost value="localhost" />
    <authentication value="None" />
    <port value="25" />
    <bufferSize value="1" />
    <lossy value="false" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%utcdate [%level] - %message%newline%exception" />
    </layout>
  </appender>
  <root>
    <level value="All" />
    <appender-ref ref="SmtpAppender" />
  </root>
</log4net>

这是Program.cs

And this is Program.cs

namespace Log4NetTest
{
    public class Program
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));

        static void Main(string[] args)
        {
            XmlDocument log4netConfig = new XmlDocument();
            log4netConfig.Load(File.OpenRead("log4net.config"));

            var repo = log4net.LogManager.CreateRepository(Assembly.GetEntryAssembly(), 
                typeof(log4net.Repository.Hierarchy.Hierarchy));

            log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]);
            log.Info("TEST INFO LOG");
        }

    }
}

运行应用程序时,我希望将一封电子邮件发送给本地主机,并显示消息"TEST INFO LOG",但log4net会将其输出到控制台:

When I run the application, I expect an email to be sent to localhost with the message "TEST INFO LOG" but instead log4net outputs this to the console:

log4net:ERROR Could not create Appender [SmtpAppender] of type [log4net.Appender.SmtpAppender]. Reported error follows.
System.TypeLoadException: Could not load type 'log4net.Appender.SmtpAppender' from assembly 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'.
   at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive)
   at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR Appender named [SmtpAppender] not found.
Press any key to continue . . .

SmtpAppender类型甚至没有出现在对象浏览器中.有SmtpPickupDirAppender,但这不是我要使用的.

SmtpAppender type does not even appear in the object browser. There's SmtpPickupDirAppender but that's not what I want to use.

我想念什么吗?经过一番搜索,我没有发现任何人遇到过此问题,log4net 2.0.8已有7个月的历史,并且下载了milion次.

Do I miss something? After some search I did not find anyone ever had this problem, log4net 2.0.8 is 7 months old and downloaded milion times.

推荐答案

由于内置了SmtpAppender ,您可以轻松地为Log4Net创建自己的自定义SMTP附加程序.看看

Since the built in SmtpAppender is not supported for .Net Core, you can quite easily create your own custom SMTP appender for Log4Net. Take a look at

https://github.com/HatfieldConsultants/Log4Net.Core.CustomAppenders

作为如何构建非常基本的SMTP附加程序的示例.

as an example of how a very basic SMTP appender can be built.

这篇关于log4net 2.0.8 nuget中缺少SmtpAppender吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆