Entreprise Library Logging and WCF Services

Topics: Logging Application Block
Jul 17, 2008 at 9:02 PM
Hi,

I have one class library doing log routine, the log files are created in C:\bds\componente.log, this address is configurated in web.config file in the application that uses the library, in my case the WCF service. The service calls a method that calls Logger.Write(), this class has the categorie that I put in web.config but nothing happens after the call with the necessary parameters. I think the problem is permission but cant know for sure.

Thx.

Navarro.
Jul 17, 2008 at 10:52 PM
If you can attach a debugger to the WCF service process, you can add a System.Diagnostics.DefaultTraceListener to the "Logging Errors & Warnings" special source in the service's configuration file. This will write any errors that occurred while logging to the debugger's output window. You can add such a debugger as a "System.Diagnostics TraceListener".

Hope this helps,
Fernando


vnavarro87 wrote:
Hi,

I have one class library doing log routine, the log files are created in C:\bds\componente.log, this address is configurated in web.config file in the application that uses the library, in my case the WCF service. The service calls a method that calls Logger.Write(), this class has the categorie that I put in web.config but nothing happens after the call with the necessary parameters. I think the problem is permission but cant know for sure.

Thx.

Navarro.


Jul 18, 2008 at 2:23 PM
Hi,

I did what you said to, but it appears that nothing happens, when I debug my web application and enter in the WCF service (testing in the same machine) it executes the code pass trought the Logger.Write(LogEntry) normally, dont show anything in output window and dont put my file in the choosen path. The following code one line above the Logger.Write(LogEntry) works fine: 

File

 

.Create(@"C:\bds\teste.txt");

I'm really  confuse right now.

Thx.
Navarro.

 

Jul 18, 2008 at 2:47 PM

Hi,

Is there any filter that might be causing problems? In any case, you can always get the PDB files for entlib from http://www.codeplex.com/entlib/Release/ProjectReleases.aspx?ReleaseId=13498 use them to step into EntLib's source to see what's going on.

Fernando

 


vnavarro87 wrote:
Hi,

I did what you said to, but it appears that nothing happens, when I debug my web application and enter in the WCF service (testing in the same machine) it executes the code pass trought the Logger.Write(LogEntry) normally, dont show anything in output window and dont put my file in the choosen path. The following code one line above the Logger.Write(LogEntry) works fine: 

File

 

.Create(@"C:\bds\teste.txt");

I'm really  confuse right now.

Thx.
Navarro.

 

 




Jul 18, 2008 at 3:20 PM
Hi,
Sorry for asking this, but I search info about it and didnt found any. How do I step into EntLib's source? I add the pbd's file of the .dll's that are in my project and when debugging I try an F11 command and VS2008 simply dont step into it, the source code is installed in the machine. I'm doing something wrong?

Thx.

Navarro.
Jul 18, 2008 at 3:26 PM
Make sure the PDB files are in the same folder where the binaries are installed, and that they are copied to where you're running the application from. You can check whether they are loaded by opening the modules window (Debug/Windows/Modules while debugging) and looking at the symbol status column. You may also need to uncheck the "Enable Just My Code" option (Tools/Options/Debugging).

When you step into, you should be prompted for the location of the source code file; just browse to the folder where you installed the source code.

Hope this helps,
Fernando


vnavarro87 wrote:
Hi,
Sorry for asking this, but I search info about it and didnt found any. How do I step into EntLib's source? I add the pbd's file of the .dll's that are in my project and when debugging I try an F11 command and VS2008 simply dont step into it, the source code is installed in the machine. I'm doing something wrong?

Thx.

Navarro.


Jul 18, 2008 at 4:03 PM

Hi,

When debugging the Logger.Write(LogEntry) I step into this method

 

public

 

static LogWriter Writer

 

{

 

get

 

 

 

 

{

 

if (writer == null)

 

{

 

lock (sync)

 

{

 

if (writer == null)

 

{

 

try

 

 

 

 

{

writer = factory.Create();

}

 

catch (ConfigurationErrorsException configurationException)

 

{

TryLogConfigurationFailure(configurationException);

 

throw;

 

}

}

}

}

 

return writer;

 

}

 


First this writer object dont seems to be null but in the first if(writer == null) it passes in to the next part of the code like if writer is null then in the line of lock(sync) it steps out, this part I cant understand quite well, it appears to me that this isnt right and this is the cause for not doing the log.

Thx.

Navarro

Jul 18, 2008 at 4:12 PM
Hi,

I did a test with my win forms application that uses the same logging library and debug the same class Logger.Write(LogEntry) with exactly the same parameters and it passes by lock(sync) code and creates the log file. Hope that helps you to help me identifie the problem hehehehe.

Thx.

Navarro.
Jul 18, 2008 at 6:21 PM
The code to create the Logger's LogWriter should not be relevant unless it fails, in which case you need to determine why it failed by looking at the exception that is thrown. Assuming it doesn't, you need to debug the implementation of LogWriter.Write(LogEntry).

Fernando

vnavarro87 wrote:
Hi,

I did a test with my win forms application that uses the same logging library and debug the same class Logger.Write(LogEntry) with exactly the same parameters and it passes by lock(sync) code and creates the log file. Hope that helps you to help me identifie the problem hehehehe.

Thx.

Navarro.


Jul 18, 2008 at 6:33 PM
Hi,

Sorry I didnt express very well, that code is from EntLib 4, its not my code, and it doesnt throw an exception simply cant lock at lock(sync), that is an internal issue from EL 4, I cant understand why EL4 could not lock and what it is trying to lock, the code dont do anything more than that I show above.

Thx.

Navarro.
Jul 18, 2008 at 7:20 PM
What do you mean by "can't lock at lock(sync)"? Does it just stay frozen in that line, waiting to acquire the lock? Check how many threads are trying to acquire this lock, it's possible another thread has it already.

Fernando


vnavarro87 wrote:
Hi,

Sorry I didnt express very well, that code is from EntLib 4, its not my code, and it doesnt throw an exception simply cant lock at lock(sync), that is an internal issue from EL 4, I cant understand why EL4 could not lock and what it is trying to lock, the code dont do anything more than that I show above.

Thx.

Navarro.


Aug 1, 2008 at 6:25 PM

Hi,

Sorry for such a long time to reply but I had some issues to solve before this. You're right another thread its trying to get access but its trought the same app, WCF do more than one call to a method so that methods call this specific functions  more than one time, but not with the same thread, this is not mine major concern, the problem is when I get by the lock statement  in the try catch block it passes by the writer = factory.Create(); then acess the catch like if it an error has ocurred but  

 

ConfigurationErrorsException configurationException

 

 object is null
then debugger jumps into the factory back like if the catch didn't ocurred and enter in LogWriter Create() then 

 

return

 

EnterpriseLibraryFactory.BuildUp<LogWriter>(configurationSource);

 

 

then

 

return

 

BuildUp<T>(null, null, configurationSource);

 

 

configurationSource isn't null but inside BuildUp magically it appears like null and access the throw new ArgumentNullException("configurationSource");
but this doesnt stops the code (weird) and the execution do the try catch block next trying this method GetObjectBuild() then debuggers enter in catch again but i cant see what is in BuildFailsedException e neither ConfigurationErrorsException cee = GetConfigurationErrosException(e); that is not null but not visible, then it goes back throwing something I cant figure what or why and returns normaly to execution without any erros in my screen or something logged in the file that I asked to. The only message comes from the Write(LogEntry log) method: "Log writer failed to acquire lock while writing log entry."
at TryLogLockAcquisitionFailure(Resources.ExceptionFailedToAcquireLockToWriteLog); the message is inside the Resources.ExceptionfailedToAcquireLockToWriteLog.

I cant even understand it quite well its so confuse that I hope not confunsing you too.

Thank you and sorry for such a problem.