Base solution for your next web application
Open Closed

Why aren't my debug message in logs.txt? Probably stupid question #11129


User avatar
0
marble68 created

Prerequisites

V11.0 MVC Core

I created a domain service, and it's called by a background job.

Everything works fine.

I want to log output to the application log file specified in the log4net configuration.

I follow the instructions here: aspnetboilerplate logging documentation as instructed to by documentation here: AspNetZero Core MVC Documentation on logging

I did this:

using Abp.Dependency;
using nameSpace.Surpath.Importing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Castle.Core.Logging;

namespace nameSpace.Surpath.DomainServices
{

    public class ImportClientFromSPLService : nameSpaceServiceBase, IImportClientFromSPLService, ISingletonDependency
    {
        public ILogger Logger { get; set; }

        public bool CanImport { get; set; } = true;

        public ImportClientFromSPLService()
        {
            Logger = NullLogger.Instance;

        }

        public async Task<bool> DoImport(JobArguments args)
        {
            if (CanImport)
            {
                Logger.Debug($"DoImport called (Starting): client_id= {args.client_id}");
                
                CanImport = false;
                return true;
                Thread.Sleep(10000);
                Logger.Debug($"DoImport called (Finished): client_id= {args.client_id}");
                CanImport = true;
            }
            else
            {
                Logger.Debug($"DoImport called (Busy): client_id= {args.client_id}");
                return false;
            }

        }
    }
}

I run it, my "DoImport" method is called, and nothing is logged in my Logs.txt file.

I'm obviously doing something really silly here, missing something very basic.

Any suggestions why this doesn't work?


1 Answer(s)
  • User Avatar
    0
    marble68 created

    Yes, it was something stupid..

    Fixed by job doing the following:

    ImportClientFromSPLService(){Logger=Logger}.DoImport(args);