Log4J Issue -> [Fatal Error] :1:1: Content is not allowed in prolog
<p>Since last week I'm getting this strange error. without any modification to my code, which is given below.</p>

<p>I went through the SO Answers around same error but most of those refer xml parsing issue, which in my case it's not at all.</p>

<p>Another strange thing is that it's not giving me the stack trace, please read out the comments in the code for the clarity</p>

<pre><code>private void initializeLoggerContext(Properties properties) throws IOException {
        System.out.println("initializeLoggerContext : Properties -&gt; " + properties.toString());
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        properties.store(output, null);
        ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
        Configuration conf = null;
        try {
            ConfigurationSource c = new ConfigurationSource(input);
            //conf = PropertiesConfigurationFactory.getInstance().getConfiguration(new ConfigurationSource(input));
            ConfigurationFactory conffact = PropertiesConfigurationFactory.getInstance();
            System.out.println("ConfigurationFactory conffact = " + conffact.toString());
            //ERROR : below line prints message on the console as "[Fatal Error] :1:1: Content is not allowed in prolog." with no stack trace
            conf = conffact.getConfiguration(c);
            final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
            ctx.start(conf);
            LOGGER.info("Logging configuration is : {}", ctx);
        } catch(Exception e) {//Note getting called when getting "[Fatal Error] :1:1: Content is not allowed in prolog." on the console
            System.out.println("initializeLoggerContext : Exception is -&gt; ");
            e.printStackTrace();
        }
    }
</code></pre>

<p>I've created a sample app below with the original input properties but still it's failing with the log4j 2.5. When I tried with the simple property with one key-value pair then also the result was same. Please check the code below :</p>

<pre><code>import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringBufferInputStream;
import java.util.Properties;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EcommLoggingIssueByDeven {

    private static final Logger LOGGER = LoggerFactory.getLogger(EcommLoggingIssueByDeven.class);

    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        String str = "appender.jdbc.policies.type=Policies"
                + ", logger.xmanager.appenderRefs=xmanager"
                + ", appender.remedy.fileName=${remedyfilename}"
                + ", logger.xmanager.additivity=false"
                + ", appender.eventFramework.layout.pattern=%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+0} %p %env %appDetail  [%t] %l %customInfo%msgInfo %n"
                + ", appender.spring.layout.type=PatternLayout"
                + ", appender.application.fileName=${appfilename}"
                + ", appender.scm.policies.size.type=SizeBasedTriggeringPolicy"
                + ", appender.scm.layout.type=PatternLayout"
                + ", appender.remedy.filePattern=${sys:ECOMM_HOME}/logs/filename-%i.log.gz"
                + ", logger.jdbc.additivity=false"
                + ", appender.application.type=RollingFile"
                + ", rootLogger.appenderRefs=application"
                + ", appender.eventFramework.policies.size.size=1MB"
                + ", appender.application.strategy.max=10"
                + ", appender.spring.type=RollingFile"
                + ", appender.remedy.policies.size.type=SizeBasedTriggeringPolicy"
                + ", appender.eventFramework.policies.type=Policies"
                + ", status=info"
                + ", property.eventFrameworkfilename=${sys:ECOMM_HOME}/logs/filename.log"
                + ", logger.application.level=DEBUG"
                + ", appender.remedy.name=remedy"
                + ", appender.application.policies.type=Policies"
                + ", logger.remedy.name=com.ecommerce.fulfillment.external.remedy"
                + ", logger.jdbc.appenderRef.jdbc.ref=jdbc"
                + ", logger.remedy.level=INFO"
                + ", logger.remedy.appenderRefs=remedy"
                + ", appender.application.filePattern=/log/ecomm-logging/app-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz"
                + ", appender.spring.fileName=${springfilename}"
                + ", logger.eventFramework.appenderRef.eventFramework.ref=eventFramework"
                + ", appender.scm.policies.size.size=1MB"
                + ", logger.eventFramework.name=com.ecommerce.fulfillment.common.eventframework"
                + ", property.appfilename=/log/ecomm-logging/app.log"
                + ", appender.console.layout.pattern=%m%n"
                + ", appender.eventFramework.layout.type=PatternLayout"
                + ", appender.spring.policies.type=Policies"
                + ", appender.config.layout.type=PatternLayout"
                + ", logger.scm.level=INFO, rootLogger.level=INFO"
                + ", appender.spring.strategy.max=5"
                + ", appender.remedy.policies.size.size=1MB"
                + ", logger.application.appenderRefs=application"
                + ", appender.application.name=application"
                + ", appender.xmanager.layout.pattern=%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+0} %p %env %appDetail  [%t] %l %customInfo%msgInfo %n"
                + ", appender.spring.name=spring"
                + ", appender.jdbc.type=RollingFile"
                + ", appender.jdbc.layout.type=PatternLayout"
                + ", logger.spring.name=org.springframework"
                + ", logger.jdbc.appenderRefs=jdbc"
                + ", logger.scm.name=com.platform"
                + ", appender.scm.layout.pattern=%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+0} %p %env %appDetail  [%t] %l %customInfo%msgInfo %n"
                + ", property.scmfilename=${sys:ECOMM_HOME}/logs/filename.log, logger.spring.appenderRef.spring.ref=spring"
                + ", logger.xmanager.level=INFO"
                + ", appender.xmanager.layout.type=PatternLayout"
                + ", appender.spring.layout.pattern=%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+0} %p %env %appDetail  [%t] %l %customInfo%msgInfo %n"
                + ", appender.scm.filePattern=${sys:ECOMM_HOME}/logs/filename-%i.log.gz"
                + ", appender.jdbc.policies.size.type=SizeBasedTriggeringPolicy"
                + ", logger.config.level=INFO"
                + ", logger.eventFramework.level=INFO"
                + ", appender.config.strategy.max=5"
                + ", appender.config.policies.size.type=SizeBasedTriggeringPolicy"
                + ", appender.spring.policies.size.type=SizeBasedTriggeringPolicy"
                + ", logger.remedy.additivity=false, logger.jdbc.level=INFO"
                + ", appender.scm.type=RollingFile"
                + ", name=PropertiesConfig"
                + ", appender.eventFramework.strategy.max=5"
                + ", appender.scm.strategy.type=DefaultRolloverStrategy"
                + ", logger.application.name=com.ecommerce.fulfillment"
                + ", appender.xmanager.fileName=${xmanagerfilename}"
                + ", appender.scm.fileName=${scmfilename}"
                + ", rootLogger.appenderRef.application.ref=application"
                + ", logger.application.additivity=false"
                + ", appender.spring.filePattern=${sys:ECOMM_HOME}/logs/filename-%i.log.gz"
                + ", appender.xmanager.type=RollingFile"
                + ", appender.xmanager.policies.size.type=SizeBasedTriggeringPolicy"
                + ", appender.jdbc.strategy.type=DefaultRolloverStrategy"
                + ", appender.eventFramework.fileName=${eventFrameworkfilename}"
                + ", logger.spring.appenderRefs=spring"
                + ", appender.config.policies.type=Policies"
                + ", appender.jdbc.layout.pattern=%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+0} %p %env %appDetail  [%t] %l %customInfo%msgInfo %n"
                + ", appender.jdbc.name=jdbc, appender.xmanager.policies.type=Policies"
                + ", appender.eventFramework.filePattern=${sys:ECOMM_HOME}/logs/filename-%i.log.gz"
                + ", appender.jdbc.policies.size.size=3MB"
                + ", property.configfilename=/log/ecomm-logging/config1.log"
                + ", appender.console.layout.type=PatternLayout"
                + ", appender.config.policies.size.size=1MB"
                + ", appender.spring.policies.size.size=3MB"
                + ", loggers=application,config,eventFramework,jdbc,remedy,scm,spring,xmanager"
                + ", logger.scm.appenderRef.scm.ref=scm"
                + ", appender.config.filePattern=/log/ecomm-logging/config-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz"
                + ", logger.config.appenderRef.config.ref=config"
                + ", appender.eventFramework.strategy.type=DefaultRolloverStrategy"
                + ", appender.scm.name=scm"
                + ", logger.config.appenderRefs=config"
                + ", appender.xmanager.policies.size.size=5MB"
                + ", appender.config.fileName=${configfilename}"
                + ", appender.jdbc.filePattern=${sys:ECOMM_HOME}/logs/filename-%i.log.gz"
                + ", appenders=application,config,eventFramework,jdbc,remedy,scm,spring,xmanager"
                + ", appender.remedy.policies.type=Policies"
                + ", appender.xmanager.name=xmanager"
                + ", property.xmanagerfilename=${sys:ECOMM_HOME}/logs/filename.log"
                + ", logger.spring.level=INFO"
                + ", appender.application.policies.size.type=SizeBasedTriggeringPolicy"
                + ", logger.xmanager.appenderRef.xmanager.ref=xmanager"
                + ", property.filename=/log/ecomm-logging/test.log"
                + ", logger.eventFramework.appenderRefs=eventFramework"
                + ", appender.application.strategy.type=DefaultRolloverStrategy"
                + ", appender.spring.strategy.type=DefaultRolloverStrategy"
                + ", logger.spring.additivity=false"
                + ", logger.application.appenderRef.application.ref=application"
                + ", appender.xmanager.filePattern=${sys:ECOMM_HOME}/logs/filename-%i.log.gz"
                + ", logger.scm.appenderRefs=scm"
                + ", appender.scm.strategy.max=5"
                + ", appender.console.type=Console"
                + ", logger.eventFramework.additivity=false"
                + ", appender.application.policies.size.size=5MB"
                + ", appender.jdbc.strategy.max=5"
                + ", logger.remedy.appenderRef.remedy.ref=remedy"
                + ", appender.config.type=RollingFile"
                + ", appender.eventFramework.type=RollingFile"
                + ", appender.jdbc.fileName=${jdbcfilename}"
                + ", logger.scm.additivity=false"
                + ", property.remedyfilename=${sys:ECOMM_HOME}/logs/filename.log"
                + ", appender.application.layout.pattern=%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+0} %p %env %appDetail  [%t] %l %customInfo%msgInfo %n"
                + ", logger.config.name=com.ecommerce.fulfillment.common.configuration"
                + ", logger.xmanager.name=com.ecommerce.fulfillment.common.xmanagerframework"
                + ", appender.config.strategy.type=DefaultRolloverStrategy"
                + ", appender.remedy.layout.pattern=%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+0} %p %env %appDetail  [%t] %l %customInfo%msgInfo %n"
                + ", appender.application.layout.type=PatternLayout"
                + ", appender.remedy.layout.type=PatternLayout"
                + ", appender.xmanager.strategy.type=DefaultRolloverStrategy"
                + ", appender.config.layout.pattern=%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+0} %p %env %appDetail  [%t] %l %customInfo%msgInfo %n"
                + ", logger.config.additivity=false"
                + ", appender.console.name=STDOUT"
                + ", property.jdbcfilename=${sys:ECOMM_HOME}/logs/filename.log"
                + ", appender.config.name=config"
                + ", appender.eventFramework.name=eventFramework"
                + ", appender.xmanager.strategy.max=5"
                + ", packages=com.ecommerce.logging.plugins"
                + ", logger.jdbc.name=org.springframework.jdbc.core"
                + ", appender.remedy.strategy.type=DefaultRolloverStrategy"
                + ", appender.remedy.strategy.max=5"
                + ", appender.remedy.type=RollingFile"
                + ", appender.scm.policies.type=Policies"
                + ", appender.eventFramework.policies.size.type=SizeBasedTriggeringPolicy"
                + ", property.springfilename=${sys:ECOMM_HOME}/logs/filename.log";
        properties.load(new StringBufferInputStream(str));
        System.out.println("Properties -&gt; " + properties.toString());
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        properties.store(output, null);
        ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
        Configuration conf = null;
        conf = PropertiesConfigurationFactory.getInstance().getConfiguration(new ConfigurationSource(input));
        final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        ctx.start(conf);
        LOGGER.info("Logging configuration is : {}", ctx);
    }
}
</code></pre>