.Net Core WebApi 接入Log4Net

1.添加引用

Install-Package log4net

2.添加log4net.config 配置文件



  
  
    
      
    
    
    
      
      
      
        
      
    

    
      
      
      
      
      
      
      
      
        
      
    

    
    
      
      
      
      
    

  

3.Startup修改

public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
            repository = LogManager.CreateRepository("NETCoreRepository");
            XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
        }

4.类中调用

static ILog log = LogManager.GetLogger(Startup.repository.Name, typeof(AddressMatchService));
log.Info("helloworld");
AddressMatchService为类名

你可能感兴趣的:(.Net,Core,开发中遇到的问题记录)