Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Logging issue #10063


User avatar
0
alexanderpilhar created

10.2.0, Angular

Please, also see log4net stopped generating the logs.

I think there is an issue with logging configuration!? Since ASPNETZERO 10.0.0 logging stopped to work in debug environment but was still working in production environment. Since ASPNETZERO 10.2.0 logging is working in debug environment but stopped to work in production environment.

ASPNETZERO-Team, please confirm if there is a problem.


15 Answer(s)
  • User Avatar
    0
    alexanderpilhar created

    In my production environment I just changed log4net.config from <file value="../../../App_Data/Logs/Logs.txt" /> to <file value="App_Data/Logs/Logs.txt" /> and recycled the application pool on IIS. Now logging is working as expected again.

    I think production environment should use log4net.Production.config, right?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @alexanderpilhar

    Yes, you are right. for Production, log4net.Production.config must be used. As I can see, latest version has this code block https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Public/Startup/Startup.cs#L73. Could you compare it with your project ?

  • User Avatar
    0
    alexanderpilhar created

    Hi @ismcagdas

    Yes, it's the same code (left side: current project; right side: original ASPNETZERO 10.2.0)

  • User Avatar
    0
    alexanderpilhar created

    The only thing I can see is the following:

    ~~In the Code above the file is named log4net.Production.config but actual file name is log4net.production.config (P vs p). Could this be the problem?~~ *

    EDIT Hm, when published file name is log4net.Production.config again (with P).

    EDIT * I was wrong about this: actual file name is log4net.Production.config, I confused it with appsettings.production.config ....

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    In that case, I think log4net.Production.config will be used but maybe the path in log4net.Production.config is wrong. Could that be the reason ?

  • User Avatar
    0
    alexanderpilhar created

    Path in log4net.Production.config ist correct/working (<file value="App_Data/Logs/Logs.txt" />). But it doesn't matter as it is not what is being used (log4net.config is used instead).

  • User Avatar
    0
    musa.demir created

    Hi @alexanderpilhar

    As you both mentioned there are two config file. log4net.config: For development environment log4net.Production.config: For production environment,

    When you debug your code, logs will be written to aspnet-core\src\[YOURAPPNAME].Web.Host\App_Data\Logs\Logs.txt As set here: https://github.com/aspnetzero/aspnet-zero-core/blob/f0acf27b6151e2993af2abbc647968f1f578f91f/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Host/log4net.config#L4

    When you publish your code, logs will be written to [YOURPUBLISHFOLDER]\App_Data\Logs\Logs.txt As set here: https://github.com/aspnetzero/aspnet-zero-core/blob/f0acf27b6151e2993af2abbc647968f1f578f91f/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Host/log4net.Production.config#L4

    Is it not working as expected on your app?

  • User Avatar
    0
    alexanderpilhar created

    Hi @musa.demir

    Yes, that is what i was expecting.

    But it turns out both my environments (dev and prod) use log4net.config instead of production environment using log4net.Production.config.

    BTW, this is also true vor appsettings.json (used by dev and prod) instead of appsettings.production.json being used for production environment.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @alexanderpilhar

    Could you log somewhere to see if your app's environment is set to Production ?

  • User Avatar
    0
    alexanderpilhar created

    Build configuration is set to Release in my publishing-profile.

    @ismcagdas, sorry, but I don't understand what you want me to do - what do you mean with 'could you log somewhere' !?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    For example, you can get this infor in a controller like this https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Host/Controllers/HomeController.cs#L26 and Log it using the Logger.

  • User Avatar
    0
    alexanderpilhar created

    Hi @ismcagdas,

    I managed to log the environment as requested and it says 'Development'. Do I miss some configuration?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @alexanderpilhar

    Sorry for my late reply. Could you share how do you deploy your app ? It might be related to that. You can set environment variable on the deployed server to easily fix this.

  • User Avatar
    0
    alexanderpilhar created

    Hm ... I checked system variables on server and found out that ASPNETCORE_ENVIRONMENT is set to Development globally.

    Also see: Use multiple environments in ASP.NET Core / Set environment on Windows

    I'll have to contact our sys admin to check whether this is on purpose.

  • User Avatar
    0
    alexanderpilhar created

    Yes, after removing the system variable and restarting the server everything is working as expected - thanks for helping me to figure this out!