0

I'm trying to setup loggly with a C# projet by following the Loggly tutorial but it doesn't work.

I've added the log4net-loggly nuget package

I've add the following code in my app.config :

<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>

<log4net>
  <root>
    <level value="ALL" />
    <appender-ref ref="LogglyAppender" />
  </root>
  <appender name="LogglyAppender" type="log4net.loggly.LogglyAppender, log4net-loggly">
    <rootUrl value="https://xxxxx.loggly.com/" />
    <inputKey value="XXXXX" />
    <tag value="log4net" />
  </appender>
</log4net>

And this is how I'm trying to send logs to Loggly :

var logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
logger.Error("your log message", new Exception("your exception message"));

I've debugged with Fiddler to see if there was a request to Loggly but there is nothing.

What am I missing ?

Alex Caron
  • 27
  • 3
  • Are you loading the log4net configuration at startup? – stuartd Dec 04 '18 at 16:08
  • Nope.. I thought only with app.config I would be OK – Alex Caron Dec 04 '18 at 16:42
  • No, you need to explicitly load the config - add a call to [`XmlConfigurator.Configure()`](https://logging.apache.org/log4net/release/sdk/html/M_log4net_Config_XmlConfigurator_Configure.htm) during app startup. – stuartd Dec 04 '18 at 16:43
  • this is an empty c# projet with only one class.. Can I call it just before `var logger` ? – Alex Caron Dec 04 '18 at 16:45
  • Anyway, I'd already add it to my AssemblyInfo – Alex Caron Dec 04 '18 at 16:50
  • Using the assembly call [has it's quirks](http://logging.apache.org/log4net/release/manual/configuration.html#attributes) but should work with just one class. I suggest you [enable log4net internal debugging](https://stackoverflow.com/questions/756125/how-to-track-down-log4net-problems) and see what that's reporting. – stuartd Dec 04 '18 at 16:55

1 Answers1

1

install the Microsoft.CSharp package in your solution. This library is necessary to use the C# dynamic data types.