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

Core Template Not Logging #2535


User avatar
0
codemonkey21 created

I restarted my project on a fresh core template (v 1.4.2 at the time of download). It appears that that it should in theory write logs out of the box, however no log file has been generated. I've attemped to manually write to the log calling the Logger in an app service and that also does not generate any results. Now that I need to debug, I desperately need the log file.

I even tried to manually create a default blank logs.txt file.

project.web references are; abp.castle.log4net (1.4.2) castle.loggingfacility.mslogging (1.1.0)

From project.web startup.cs

public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            //MVC
            services.AddMvc(options =>
            {
                options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
            });

            //Configure Abp and Dependency Injection
            return services.AddAbp<NyxlyWebModule>(options =>
            {
                //Configure Log4Net logging
                options.IocManager.IocContainer.AddFacility<LoggingFacility>(
                    f => f.UseAbpLog4Net().WithConfig("log4net.config")
                );
            });
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseAbp(); //Initializes ABP framework.

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            AuthConfigurer.Configure(app, _appConfiguration);

            app.UseStaticFiles();

            //Integrate to OWIN
            app.UseAppBuilder(ConfigureOwinServices);

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "defaultWithArea",
                    template: "{area}/{controller=Home}/{action=Index}/{id?}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseMiddleware<BeginRequest>(env);
        }

from log4net.config

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender" >
    <file value="App_Data/Logs/Logs.txt" />
    <appendToFile value="true" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="10000KB" />
    <staticLogFileName value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-5level %date [%-5.5thread] %-40.40logger - %message%newline" />
    </layout>
  </appender>
  <root>
    <appender-ref ref="RollingFileAppender" />
    <level value="DEBUG" />
  </root>
  <logger name="NHibernate">
    <level value="WARN" />
  </logger>
</log4net>

8 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Your configuration seems correct. Do you run the project on Visual Studio or is it published to IIS ? Maybe environment does not have write access to specified folder ?

  • User Avatar
    0
    codemonkey21 created

    I'm just running locally from Visual Studio. I'm using VS Express 2015 and run as admin.

    I'm also seeing a fair amount in the output console of VS with missing PBDs and the following;

    Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll Exception thrown: 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' in Microsoft.CSharp.dll

  • User Avatar
    0
    codemonkey21 created

    Okay, I found a Logs.txt in my project, but it seems like it's in the wrong spot.

    project.web/bin/debug/net461/win7-x64/App_Data/Logs.txt

    but I assumed it would be at project.web/App_Data/Logs.txt

  • User Avatar
    0
    ismcagdas created
    Support Team

    Ok, in Core version, it is placed there.

  • User Avatar
    0
    epro1 created

    Hello,

    I'm using Angular 2 + .NET core tempate and I have the same configuration as @codemonkey21. My project references are: abp.castle.log4net (1.5.1) castle.loggingfacility.mslogging (1.1.0)

    Startup.cs

    public IServiceProvider ConfigureServices(IServiceCollection services)
            {
                //MVC
                services.AddMvc(options =>
                {
                    options.Filters.Add(new CorsAuthorizationFilterFactory(DefaultCorsPolicyName));
                });
    
                //Configure CORS for angular2 UI
                services.AddCors(options =>
                {
                    options.AddPolicy(DefaultCorsPolicyName, p =>
                    {
                        //todo: Get from confiuration
                        p.WithOrigins("http://localhost:4200").AllowAnyHeader().AllowAnyMethod();
                    });
                });
    
                //Swagger - Enable this line and the related lines in Configure method to enable swagger UI
                services.AddSwaggerGen();
    
                
    
                //Configure Abp and Dependency Injection
                return services.AddAbp<SuperhikWebHostModule>(options =>
                {
                    //Configure Log4Net logging
                    options.IocManager.IocContainer.AddFacility<LoggingFacility>(
                        f => f.UseAbpLog4Net().WithConfig("log4net.config")
                    );
                });
            }
    

    log4net.config

    <?xml version="1.0" encoding="utf-8" ?>
    <log4net>
      <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender" >
        <file value="App_Data/Logs/Logs.txt" />
        <appendToFile value="true" />
        <rollingStyle value="Size" />
        <maxSizeRollBackups value="10" />
        <maximumFileSize value="10000KB" />
        <staticLogFileName value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%-5level %date [%-5.5thread] %-40.40logger - %message%newline" />
        </layout>
      </appender>
      <root>
        <appender-ref ref="RollingFileAppender" />
        <level value="DEBUG" />
      </root>
    </log4net>
    

    I can't find log file on location that @codemonkey21 find his or in any other part of my project. I tried to change location of file in log4net.config but nothing helps. What could be the problem? Is there any way to debug log4net?

    Any help would be appreciated

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    With the default configuration it should be placed under *.Web.Host project's bin folder in development mode. Maybe your windows user does not have write access in that folder, could it be possible ?

    Thanks.

  • User Avatar
    0
    epro1 created

    Hi,

    I figured out what was the problem. The problem was in encoding of log4net.config file. I changed encoding to UTF-8 without BOM and I now can se logs.txt file under *.WebHost project's bin folder.

    Regards.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @epro1,

    Thanks for your feedback, I think it will help others as well.