3

From inside a Asp.Net Web Api Application (version 5) I am trying to send logs to LogEntries but cannot. With the same code and configuration, I can send the logs successfully from localhost.

This is the code I am using to send the logs (with NLog:)

private static Logger log = LogManager.GetCurrentClassLogger();

public static void LogString(string message)
{
    log.Error(builder.ToString());
}

This is the web.config configuration:

<appSettings>
    <add key="Logentries.Token" value="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />
</appSettings>

<nlog>
<extensions>
  <add assembly="LogentriesNLog" />
</extensions>
<targets>
  <target name="logentries" type="Logentries" debug="true" httpPut="false" ssl="false" layout="${date:format=ddd MMM dd} ${time:format=HH:mm:ss} ${date:format=zzz yyyy} ${logger} : ${LEVEL}, ${message}" />
</targets>
<rules>
  <logger name="*" minLevel="Debug" appendTo="logentries" />
</rules>

When I run this code on production as an Azure Web App, I do not see any logs on LogEntries console. When I run this on localhost, it runs successfully.

I also tried to make a simple http request with WebRequest class to google.com and could get 200 from the server on Azure. So I think that Azure app can access to Internet but cannot / does not access to LogEntries servers for some reason.

How can I diagnose this?

Serhat Ozgel
  • 23,496
  • 29
  • 102
  • 138

2 Answers2

0

If you are on an Azure WebSite the standard System EventLog isn't there. As such that could be the issue that you are having with it not being able to apply the logs.

Here is a detailed overview of all options that you have available on Azure sites.

Mitchel Sellers
  • 62,228
  • 14
  • 110
  • 173
0

Sorry, this is a bit old, but maybe for future readers. I had the following issues with getting LogEntries working from Azure Webapps. 1) The doc is wrong about order of config settings; it reads the Azure portal settings and appsettings only AFTER it's checked it's own config. So if you have a Token on the target line, it will use that and ignore the appsetting. 2) The LogentriesCore and LogentriesNlog had to be in the application folder, NOT the location of NLog.dll. I noticed this because I was using logging from a shared library, and I had to add references to LogentriesCore and LogentriesNLog to the projects using the library, even though they shouldn't have to care.

To diagnose problems, I did these things 1) Have tracing setup in the webapp (to go to Blob storage in our case). Just use Trace.Writeline and set the tracing in Azure portal. 2) When creating my Logger I turn on exceptions first: LogManager.ThrowExceptions = true; Logger = LogManager.GetCurrentClassLogger(); 3) Turn on debug in the Logentries target line in config:

O'Rooney
  • 2,878
  • 2
  • 27
  • 41