ApplicationInsights-Java icon indicating copy to clipboard operation
ApplicationInsights-Java copied to clipboard

logging - apply layout for log4j event

Open skaabaoui opened this issue 4 years ago • 7 comments

Fix Custom layout pattern like "%d --- %m%n" can not be used with appinsights log4j v2.

The PatternLayout has no effect on the log4j sent to Azure AppInsights:

e.g:
<Configuration packages="com.microsoft.applicationinsights.log4j.v2">
    <Appenders>
        <ApplicationInsightsAppender name="aiAppender" instrumentationKey="my_instrumentation_key">
               <PatternLayout pattern="%d --- %m%n" />
        </ApplicationInsightsAppender>
    </Appenders>

    <Loggers>
        <AsyncRoot level="INFO">
            <AppenderRef ref="aiAppender" />
        </AsyncRoot>

        <!-- AsyncLogger -->
        ...  

    </Loggers>
</Configuration>

skaabaoui avatar May 15 '20 10:05 skaabaoui

CLA assistant check
All CLA requirements met.

msftclas avatar May 15 '20 10:05 msftclas

Hello @littleaj, can you please review this PR ?

skaabaoui avatar May 28 '20 07:05 skaabaoui

Hi @skaabaoui, the MDC properties should already be getting captured under customDimensions

trask avatar May 29 '20 03:05 trask

Hi @skaabaoui, the MDC properties should already be getting captured under customDimensions

Hi @trask, thank you for your feedback. the issue here that for any custom pattern that you define using PatternLayout in the log4j2.xml file, has no effect in the format of the trace displayed on appinsights.

We have always the default trace format of appinsights logs. Using this fix, we can change the trace format of the logs sent to appinsights according to our custom PatternLayout.

skaabaoui avatar May 29 '20 07:05 skaabaoui

Hi @trask, Can you please review this PR or ask someone to review it ?

skaabaoui avatar Jun 03 '20 16:06 skaabaoui

Dear Members,

Can someone please review this PR ? Thank you.

Best Regards,

skaabaoui avatar Jul 07 '20 13:07 skaabaoui

Dear Members,

Can you please review this PR ?

Kind Regards, Salah.

skaabaoui avatar Sep 10 '20 11:09 skaabaoui

Any updates on this? I have the same issue: custom logback layout is not used in App Insights

vburmus avatar May 10 '24 07:05 vburmus

@skaabaoui How did you solve it?

vburmus avatar May 10 '24 07:05 vburmus