如何用Nlog替换log4net [英] How to replace log4net with Nlog

查看:159
本文介绍了如何用Nlog替换log4net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Framework 2.0中使用的是log4net,它工作正常.现在,我正在framwork 4.0中构建一个应用程序,并且出现错误.
这是我正在使用的代码.

Hi, I was using log4net in framework 2.0, and it was working fine. Now i am building a app in framwork 4.0 and it is giving an error.
This is the code i am using.

public class DBHelper : IDisposable
    {

       private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(DBHelper));
        private const string EDK = "11d50a3a";
        private static Hashtable connStrings = new Hashtable();
        private const bool m_bUseDummyReader = true;
        DbTransaction transaction;
        IDbConnection connection;        

        private string databaseName;
        private Database CurrDB;

        cfsEncryption cfsEncrypt = new cfsEncryption();

        public DBHelper(string strDB)
        {            
            Init(strDB, IsolationLevel.ReadCommitted);
        }
        private void Init(string strDB, IsolationLevel iso)
        {

            databaseName = strDB;
            try
            {
                CurrDB = DatabaseFactory.CreateDatabase(strDB);
                connection = CurrDB.CreateConnection();
                connection.Open();
                transaction = (DbTransaction)connection.BeginTransaction();

            }
            catch (Exception ex)
            {
                if ((log.IsErrorEnabled))
                    log.Error(string.Format(System.Globalization.CultureInfo.CurrentCulture,
                        "Connection to DB ->{0} Failed", strDB), ex);

                throw;
            }
        }


这是我遇到的错误.


This is the error i am getting.

Could not load file or assembly 'log4net' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'log4net' or one of its dependencies. An attempt was made to load a program with an incorrect format

推荐答案

log4net DLL可能是为x86构建的,并且您在64位或vise上运行-反之亦然.

尝试从源代码编译log4net并更改目标平台以匹配您的主项目.
The log4net DLL was probably built for x86 and you are running on 64bit or vise-versa.

Try compiling the log4net from source and changing the target platform to match your main project.


这篇关于如何用Nlog替换log4net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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