LOg4j -获取fileName为空{参数为空:文件名}

wbrvyc0a  于 2022-11-06  发布在  其他
关注(0)|答案(1)|浏览(132)

当我运行我的应用程序时,得到的文件名为空Log4j -得到的文件名为空{参数为空:文件名} LOg4j2.yaml:-〉

Configuration:
  status: debug
  packages: com.xyz.x.log

  appenders:
    Console:
      name: LogToConsole
      PatternLayout:
        #Pattern: "%reqId%msg%n"
         Pattern: "%d{YYYY-MM-DD HH:mm:ss.SSS} [%-5level] %C{1} %L - %m%n"
    File:
      name: LogToFile
      PatternLayout:
        Pattern: "%d{YYYY-MM-DD HH:mm:ss.SSS} [%-5level]  %C{1} %L - %m%n"

  Loggers:
    logger:
      - name: com.xyz.x
        level: debug
        additivity: false
        AppenderRef:
          - ref: LogToConsole
          - ref: LogToFile
      - name: org.springframework.security
        level: debug
        additivity: false
        AppenderRef:
          - ref: LogToConsole
          - ref: LogToFile
    Root:
      level: error
      AppenderRef:
        ref: LogToConsole

我遇到的错误:

File org.apache.logging.log4j.core.config.ConfigurationException: Arguments given for element File are invalid: field 'fileName' has invalid value 'null'
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:208)
roejwanj

roejwanj1#

修改File附加器以添加 filename 属性例如:

File:
  name: LogToFile
  fileName: logs/yourLog.log
  PatternLayout:
    Pattern: "%d{YYYY-MM-DD HH:mm:ss.SSS} [%-5level]  %C{1} %L - %m%n"

相关问题