[Live Webinar] Next-Level O11y: Why Every DevOps Team Needs a RUM Strategy Register today!

Back to All Integrations

log4net log4net

Last Updated: Jun. 29, 2023

To install Coralogix.Log4net.1.2.10.Only, run the following command in the Package Manager Console –

Install-Package Coralogix.Log4net.1.2.10.Only

To install Coralogix Log4net 2.0 and Above, run the following command in the Package Manager Console –

Install-Package Coralogix.Log4net.2.0

For .NET Core, use: 

Install-Package CoralogixCoreLog4Net

General:

Private Key – Your Send-Your-Data API key is a unique ID that represents your company.

Application Name – The name of your main application, for example, a company called “SuperData” would probably insert the “SuperData” string parameter or if they want to debug their test environment they might enter the “SuperData– Test”.

SubSystem Name – Your application probably has multiple subsystems, for example, Backend servers, Middleware, Frontend servers, etc. to help you examine the data you need, inserting the subsystem parameter is vital.

Endpoint URL

If your team is part of a different Coralogix domain rather than coralogix.com, then there is a need to define an environment variable <CORALOGIX_LOG_URL> which will indicate to the specific endpoint for your team’s domain.

Create an endpoint URL by inputting your Coralogix account domain as follows:

https://api.<domain>/api/v1/logs

Via Log4NET configuration XML:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="CoralogixLog4NetAppender" type="CoralogixLog4Net.CoralogixLog4NetAppender, CoralogixLog4Net" >
    <applicationName>MyApp</applicationName>
    <subsystemName>BL</subsystemName>
    <privateKey>11111111-1111-1111-1111-111111111111</privateKey>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
    </layout>
  </appender>
  <root>
    <level value="INFO" />

Via code:

//Initilizing new CoralogixLog4Net appender.

            CoralogixLog4NetAppender coralogixAppender = new CoralogixLog4NetAppender();



            coralogixAppender.PrivateKey = "11111111-1111-1111-1111-111111111111";

            coralogixAppender.ApplicationName = "MyTestApp";

            coralogixAppender.SubsystemName = "BL";



            //Configure the Level filter for the Coralogix Appender 

            var coralogixFilter = new log4net.Filter.LevelRangeFilter();

            coralogixFilter.LevelMin = Level.All;

            coralogixAppender.AddFilter(coralogixFilter);


            log4net.Config.BasicConfigurator.Configure(coralogixAppender);


            //Adding the Coralogix log4Net appender to the Repository

            var root = ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;

            var attachable = root as IAppenderAttachable;

            if (attachable != null)

            {

                attachable.AddAppender(coralogixAppender);

            }



            // Define the actual log4net logger which through it all log entires should be reported

            ILog logger = log4net.LogManager.GetLogger(typeof(Program));


            //Activate the Coralogix appender to the log4net logger which was just created above
            coralogixAppender.ActivateOptions();

Need help? We love to assist our customers, simply reach out via our in-app chat, and we will walk you through, step by step.

On this page

Live Webinar
Next-Level O11y: Why Every DevOps Team Needs a RUM Strategy
April 30th at 12pm ET | 6pm CET
Save my Seat