首页新闻找找看学习计划

Repository [NETCoreRepository] is already defined. Repositories cannot be redefined.

0
悬赏园豆:5 [待解决问题]

.netcore 日志使用Log4Net的时候,封装个帮助类,偶尔会有这样的异常。
“Repository [NETCoreRepository] is already defined. Repositories cannot be redefined.”
private static ILog log
{
get
{
try
{
if (_log == null)
{

                    Configure();
                }
                return _log;
            }
            catch (Exception ex)
            {
                return null;
            }

        }
    }

    public static void Configure(string repositoryName = "NETCoreRepository", string configFile = "Config/log4net.config")
    {
        try
        {
            repository = LogManager.CreateRepository(repositoryName);
            XmlConfigurator.Configure(repository, new FileInfo(configFile));
            _log = LogManager.GetLogger(repositoryName, repositoryName);
        }
        catch (LogException ex)
        {
            //没有数据 
            _log = LogManager.GetLogger(repositoryName, repositoryName);
        }
        catch (Exception ex2)
        {
            //出现异常

        }


    }
冰点の爱的主页 冰点の爱 | 初学一级 | 园豆:42
提问于:2019-09-06 14:11
< >
分享
所有回答(1)
0

我猜是因为多个线程同时调用,执行了多遍repository = LogManager.CreateRepository(repositoryName);,加个小锁试试

会长 | 园豆:5012 (大侠五级) | 2019-09-06 15:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册