首页 新闻 会员 周边 捐助

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

        }


    }
沐雪架构师的主页 沐雪架构师 | 初学一级 | 园豆:67
提问于:2019-09-06 14:11
< >
分享
最佳答案
0

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

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