當我在本地計算機上啓動jar文件時,會創建兩個日誌文件,這兩個日誌文件由slog4j配置在同一個目錄中。在前一種情況下,一切正常。兩個文件被創建。但是當我從計算機通過網絡驅動器上的filemanager(TotalCmd,FAR)啓動此jar時,存在java.nio.channels.OverlappingFileLockException。網絡驅動器上的文件夾中只創建了一個第一個文件。OverlappingFileLockException在登錄時
package mypackage;
import java.util.Date;
import java.util.ResourceBundle;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import ru.mycompany.bicomp.app.BaseApp;
import ru.mycompany.db.client.TaskContext;
import ru.mycompany.form.error.JInvErrorService;
import ru.mycompany.jinvecd.impl.ECDAppImpl;
public class ECDApp extends BaseApp {
private static final ResourceBundle resource = ResourceBundle.getBundle("ecd");
private static Logger logger = Logger.getLogger("EcdAppLogger");
@Override
public String getAppID() {
return "XXI.JECD";
}
@Override
protected void initialize(String[] args) {
super.initialize(args); //To change body of generated methods, choose Tools | Templates.
configureLoggerOfApplication();
}
protected String createLoggerFileName() {
return "logs\\" + "ECDAppRootLog." + getAppID() + ".log";
}
private void configureLoggerOfApplication() {
try {
FileHandler fh = new FileHandler(createLoggerFileName(), true);
fh.setFormatter(new SimpleFormatter());
ConsoleHandler ch = new ConsoleHandler();
ch.setFormatter(new SimpleFormatter());
ch.setLevel(Level.ALL);
logger.addHandler(fh);
logger.addHandler(ch);
logger.setLevel(Level.ALL);
logger.info("------------------------Start " + new Date(System.currentTimeMillis()) + "----------------------");
} catch (Throwable ex) {
JInvErrorService.handleException(null, ex);
}
}
}
異常開始從
的FileHandler FH拋出=新的FileHandler(createLoggerFileName(),TRUE);
文件夾日誌\是存在的,因爲它是由第一記錄
protected String createDefaultLoggerFileName() {
try {
Path p = FileSystems.getDefault().getPath(".", "logs");
Files.createDirectory(p);
//Files.createDirectory((""));
} catch (IOException ex) {
}
return "logs\\" + getAppID() + ".log";
}
/**
*
*/
protected void configureDefaultLogger() throws IOException {
FileHandler fh = new FileHandler(createDefaultLoggerFileName());
fh.setFormatter(new SimpleFormatter());
Logger defaultLogger = Logger.getLogger("ru.mycompany." + getAppID());
defaultLogger.addHandler(fh);
appLog = LoggerFactory.getLogger("ru.mycompany." + getAppID());
logSystemProperties();
}
感謝的配置創建!
其實甚至沒有問題。 – Blacktempel