Hello,
I am having problem to use the Abp.Logging.LogHelper class on console apps. On my WebSite log works fine, I do the same process for my windows service app but don't work.
Heres how I initialize my service:
public static void Main(String[] args)
{
IocManager.Instance.IocContainer.AddFacility<LoggingFacility>(f => f.UseLog4Net().WithConfig("log4net.config"));
using (var bootstrapper = new AbpBootstrapper())
{
bootstrapper.Initialize();
iocManager = bootstrapper.IocManager;
LogHelper.Logger.Info("Start");
StartLoop();
}
}
I dont get any error, the LogHelper.Logger has all parameters false, so doesn't log.
On Web is like this, and works fine: protected override void Application_Start(object sender, EventArgs e) { IocManager.Instance.IocContainer.AddFacility<LoggingFacility>(f => f.UseLog4Net().WithConfig("log4net.config")); base.Application_Start(sender, e); ... }
Both log4net.config are the same, Am I missing something?
Thanks
3 Answer(s)
-
0
Short answer: Select log4net.config in the console project, open properties (F4) and select "Copy to output directory" as "Copy always"
If that does not solve your problem, check a working sample: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/AbpEfConsoleApp">https://github.com/aspnetboilerplate/as ... ConsoleApp</a>
This console app write logs.
But.... how do you use LogHelper, because it's an internal class of ABP.
-
0
Ohhh, I missed that, now its working, thanks. Its weird because on the web site I don't have the "Copy always" option selected and works, anyway.
I changed the internal to public, now that you said I think Its wrong right ? :?
So, how should I use? property injection ?
Thanks
-
0
Yes, property injection! Never use statics unless it is not avoidable.