Logging works in VS but not when deployed

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Logging works in VS but not when deployed

DeveloperM
(Apologizing for cross-posting...)

I am working in a Dynamics CRM 2011on-premises C# .Net environment. This is the first time I have used log4net so bear with me, please...

My app.config entry for log4net is:
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="EDI File Generator Log.txt" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="20MB" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
  </layout>
</appender>
<root>
  <level value="INFO"/>
  <appender-ref ref="RollingFileAppender"/>
 
</root>


In the program I have coded:
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);


And throughout the program there are several places I call a method which executes:
log.Info(sMessage);


When I execute the code from VS 2010, the program runs and messages are logged to the log file. When I deployed the program to my own machine, the program runs but no log entries are written.
Reply | Threaded
Open this post in threaded view
|

Re: Logging works in VS but not when deployed

Joseph L. Casale
> When I execute the code from VS 2010, the program runs and messages are
> logged to the log file. When I deployed the program to my own machine, the
> program runs but no log entries are written.

When you deploy, does the log4net assembly go with it as well as the app.config
with your logging configuration (renamed to match your binary)?

jlc
Reply | Threaded
Open this post in threaded view
|

Re: Logging works in VS but not when deployed

DeveloperM
Thanks for responding. The log4net reference Copy Local property is marked True.
Reply | Threaded
Open this post in threaded view
|

Re: Logging works in VS but not when deployed

Pascal ROZE
Hello

Enable the log4net internal debug to get more info.

Cheers

On 7 April 2015 at 19:21, DeveloperM <[hidden email]> wrote:
Thanks for responding. The log4net reference *Copy Local* property is marked
True.



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Logging-works-in-VS-but-not-when-deployed-tp54506p54512.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Logging works in VS but not when deployed

DeveloperM
Thanks for the suggestion, Pascal. I did that and this is what was written to the Console:

log4net: log4net assembly [log4net, Version=1.2.13.0, Culture=neutral, PublicKey
Token=669e0ddf0bb1aa2a]. Loaded from [C:\Program Files (x86)\CE\CRMEDIFileGenera
tor\log4net.dll]. (.NET Runtime [4.0.30319.18444] on Microsoft Windows NT 6.1.76
01 Service Pack 1)
log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository for assembly [MyProgram, Version=1.0.0.0,
 Culture=neutral, PublicKeyToken=null]
log4net: Assembly [MyProgram, Version=1.0.0.0, Culture=neutral, Public
KeyToken=null] Loaded From [C:\Program Files (x86)\CE\MyProgram\CRMEDI
FileGenerator.exe]
log4net: Assembly [MyProgram, Version=1.0.0.0, Culture=neutral, Public
KeyToken=null] does not have a RepositoryAttribute specified.
log4net: Assembly [MyProgram, Version=1.0.0.0, Culture=neutral, Public
KeyToken=null] using repository [log4net-default-repository] and repository type
 [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository [log4net-default-repository] using type [log4net.Re
pository.Hierarchy.Hierarchy]
log4net: configuring repository [log4net-default-repository] using file [C:\Prog
ram Files (x86)\CE\MyProgram\app.config] watching for file updates
log4net: configuring repository [log4net-default-repository] using file [C:\Prog
ram Files (x86)\CE\MyProgram\app.config]
log4net: config file [C:\Program Files (x86)\CE\MyProgram\app.config]
not found. Configuration unchanged.


Can you help me interpret this?  Certainly the app.config file was found; the correct CRM db connection is made and data is correctly returned from the instance I set in that config file.
Reply | Threaded
Open this post in threaded view
|

Re: Logging works in VS but not when deployed

Pascal ROZE
log4net: config file [C:\Program Files (x86)\CE\MyProgram\app.config]
not found

The config file was NOT found

On 7 April 2015 at 20:47, DeveloperM <[hidden email]> wrote:
Thanks for the suggestion, Pascal. I did that and this is what was written to
the Console:

log4net: log4net assembly [log4net, Version=1.2.13.0, Culture=neutral,
PublicKey
Token=669e0ddf0bb1aa2a]. Loaded from [C:\Program Files
(x86)\CE\CRMEDIFileGenera
tor\log4net.dll]. (.NET Runtime [4.0.30319.18444] on Microsoft Windows NT
6.1.76
01 Service Pack 1)
log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository for assembly [MyProgram, Version=1.0.0.0,
 Culture=neutral, PublicKeyToken=null]
log4net: Assembly [MyProgram, Version=1.0.0.0, Culture=neutral, Public
KeyToken=null] Loaded From [C:\Program Files (x86)\CE\MyProgram\CRMEDI
FileGenerator.exe]
log4net: Assembly [MyProgram, Version=1.0.0.0, Culture=neutral, Public
KeyToken=null] does not have a RepositoryAttribute specified.
log4net: Assembly [MyProgram, Version=1.0.0.0, Culture=neutral, Public
KeyToken=null] using repository [log4net-default-repository] and repository
type
 [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository [log4net-default-repository] using type
[log4net.Re
pository.Hierarchy.Hierarchy]
log4net: configuring repository [log4net-default-repository] using file
[C:\Prog
ram Files (x86)\CE\MyProgram\app.config] watching for file updates
log4net: configuring repository [log4net-default-repository] using file
[C:\Prog
ram Files (x86)\CE\MyProgram\app.config]
log4net: config file [C:\Program Files (x86)\CE\MyProgram\app.config]
not found. Configuration unchanged.


Can you help me interpret this?  Certainly the app.config file was found;
the correct CRM db connection is made and data is correctly returned from
the instance I set in that config file.




--
View this message in context: http://apache-logging.6191.n7.nabble.com/Logging-works-in-VS-but-not-when-deployed-tp54506p54514.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Logging works in VS but not when deployed

DeveloperM
This post was updated on .
Ok, why is it found when run in the IDE (VS 2010) but not when deployed?  And what needs to be done to correct this?

Update:  

Got it. The deployed config file is not "app.config"; it is MyProgram.exe.config.

I changed:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "app.config", Watch = true)]

to

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "MyProgram.exe.config", Watch = true)]

, built the solution and redeployed and it worked.  Thanks for the help.  What are best practices for making the XmlConfigurator value dynamic?

Reply | Threaded
Open this post in threaded view
|

Re: Logging works in VS but not when deployed

Pascal ROZE
Does the file exist here: C:\Program Files (x86)\CE\MyProgram\app.config ????

On 7 April 2015 at 20:56, DeveloperM <[hidden email]> wrote:
Ok, why is it found when run in the IDE (VS 2010) but not when deployed?  And
what needs to be done to correct this?



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Logging-works-in-VS-but-not-when-deployed-tp54506p54516.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Logging works in VS but not when deployed

DeveloperM
The solution was to move the [assembly: log4net.Config.XmlConfigurator] declarative to the AssemblyInfo.cs file and to not point to any particular config file.

Thanks to all who responded....
Reply | Threaded
Open this post in threaded view
|

Re: Logging works in VS but not when deployed

DeveloperM
In reply to this post by Joseph L. Casale
Joseph, thanks for the clue. You were right: the Configurator was looking for "app.config" and not the deployed config file name.