If you want all exceptions to go to the same file, use this code:
import java.io.*;import java.util.Date;public class Logger{public static synchronized logException(Exception ex){try {RandomAccessFile ff = new RandomAccessFile("c:\name.log","rw");// to append - move file pointerff.seek(ff.length());PrintWriter logWriter = new PrintWriter(new FileWriter(ff.getFD()));logWriter.println("============="+ (new Date()).toString() +ex.getMessage() + "========");ex.printStackTrace(logWriter);logWriter.println("=============================================");logWriter.close();}catch(Exception ee){//nothing to do}}}Use it as following:try{...}catch(Exception ex){ Logger.logException(ex); }
Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.























