log4j.PropertyConfigurator 运行时出错说找不到合适的配置方法(FileInputStream)

log4j.PropertyConfigurator error during runtime Says no suitable method found for configure(FileInputStream)

我在 Log4j 的构建阶段遇到以下错误。它说没有为 configure(FileInputSteam) 找到这样的方法。

以下是错误的完整上下文。

任务:compileJava 失败

E:\GadleDemoProj\src\main\java\com\hal\brands\helper\Logger\LoggerHelper.java:28: error: no suitable method found for configure(FileInputStream)
                        PropertyConfigurator.configure(inputStream);
                                            ^
    method PropertyConfigurator.configure(Properties) is not applicable
      (argument mismatch; FileInputStream cannot be converted to Properties)
    method PropertyConfigurator.configure(String) is not applicable
      (argument mismatch; FileInputStream cannot be converted to String)
    method PropertyConfigurator.configure(URL) is not applicable
      (argument mismatch; FileInputStream cannot be converted to URL)

我的记录器class如下:

 public class LoggerHelper {
    
    private static boolean root = false;
    
    public static Logger getLogger(Class clas) {
        if(root)
            return Logger.getLogger(clas);
        
        /*PropertyConfigurator.configure(ResourceHelper
                .getResourcePath("configfile/log4j.properties"));*/
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(System.getProperty("user.dir")+"\src\main\resources\configFile\log4j.properties");
            
            PropertyConfigurator.configure(inputStream);

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        root = true;
        return Logger.getLogger(clas);
    }

}

将代码更新为:

public class LoggerHelper {
    
    private static boolean root = false;
    
    public static Logger getLogger(Class clas) {
        if(root)
            return Logger.getLogger(clas);
        
        /*PropertyConfigurator.configure(ResourceHelper
                .getResourcePath("configfile/log4j.properties"));*/
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(System.getProperty("user.dir")+"\src\main\resources\configFile\log4j.properties");
            Properties properties = new Properties();
            properties.load(inputStream);
            
            PropertyConfigurator.configure(properties);

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        root = true;
        return Logger.getLogger(clas);
    }

}