@ Override public void close ( ) throws Exception { BufferedWriter writer = null ; try { FileWriter fw = new FileWriter ( file . getAbsoluteFile ( ) ) ; writer = new BufferedWriter ( fw ) ; String header = layout . getFileHeader ( ) ; if ( header != null ) { writer . append ( header ) ; } String presentationHeader = layout . getPresentationHeader ( ) ; if ( presentationHeader != null ) { writer . append ( presentationHeader ) ; } int len = buffer . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { ILoggingEvent event = buffer . get ( ) ; writer . append ( layout . doLayout ( event ) ) ; } String presentationFooter = layout . getPresentationFooter ( ) ; if ( presentationFooter != null ) { writer . append ( presentationFooter ) ; } String footer = layout . getFileFooter ( ) ; if ( footer != null ) { writer . append ( footer ) ; } } finally { if ( writer != null ) { writer . flush ( ) ; writer . close ( ) ; } } }
Close the trace and write the file