首页新闻找找看学习计划

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

0
悬赏园豆:5 [已解决问题] 解决于 2020-01-07 16:00

.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)
        {
            //出现异常

        }


    }
沐雪小程序开发者的主页 沐雪小程序开发者 | 初学一级 | 园豆:64
提问于:2019-09-06 14:11
< >
分享
最佳答案
0

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

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