log4j writing to a windows share
I have a java application running on windows machines.
Long story short, we have a convention for where we place log files per machine:
\\%COMPUTERNAME%\Logs\<AppNameHere>
So I configured my Java app to startup with -Dmachine开发者_如何学运维.name="%COMPUTERNAME%", and then in my log4j.properties file I specify
log4j.appender.R.File = \\${machine.name}\Logs\MyVerySpecialApplicationName\log.log
But I'm not seeing that directory / file show up when I run my application (the first thing the app does is log a startup message).
So my guess is that log4j / java can't process that windows specific UNC path.
Anyone else run into this issue and figure out a way around it?
I looked at Log4j's source code. It appears to use java.io.File
to hold a reference to the filename you specify.
Also, the Javadocs for java.io.File
state that UNC paths are supported for the constructor of File
(which Log4J uses).
So, on the surface, there's no reason why your configuration won't work; but — and that's the important point to note — Java has a long history of problems with file I/O over SMB (which is pretty much what you're trying to do).
My advice:
- Start your application by specifying
-Dlog4j.debug=true
. The system property will make Log4J spit lots of debug information to help you track the problem. - Attempt using the same configuration, except that, instead of referring to the file with a UNC prefix, simply map the drives (I understand that you're running on Windows). If things work with mapped drives, it means that something in using the UNC prefix is the source of the problem (although I'd doubt it).
You need to put two backlash for each one like in this configuration below
log4j.appender.Log_Arquivo.File=\\\\172.31.88.168\\server10\\soma_10\\logs\\soma_10.log
I hope this help you.
精彩评论