all groups > visual studio .net enterprise tools > march 2005 >
You're in the

visual studio .net enterprise tools

group:

Problem with Logging block


Problem with Logging block Tankut
3/24/2005 12:07:02 AM
visual studio .net enterprise tools:
Hi all,

I have developed a windows app. referencing a class library of my own and
both are using the entlib blocks. I have a configuration fileset including
logging, caching and custom config for my own data access library.
The problem is 'Logger.write("mymessage")' statements seem to do nothing
within the windows app. although the referenced class library logs without
problem (using the app's config). Using a flat file sink, text formatter.
There's no filter on category or priority.
RE: Problem with Logging block Tankut
3/24/2005 12:57:03 AM
Hi,
For anybody interested, I have spotted the issue.
The log IS written BUT guess where?
The name of the flat file sink was stated as "myfile.log" with no preceding
directory.
THe logging block opens creates file without problem in the directory my
exe is located, and writes the entries until...
The windows app. uses an openfile dialog and after the second the openfile
dialog is used A NEW log file is created at the directory where the openfile
dialog pointed earlier. But I, having seen the first file created normally
open it and see no entries after openfile action. This is the user
perspective, the BUG lies in the WriteMessageToFile method of FlatFileSink
class :
private void WriteMessageToFile(LogEntry logEntry)
{
FlatFileSinkData flatFileSinkData =
GetFlatFileSinkDataFromCursor();
string directory =
Path.GetDirectoryName(flatFileSinkData.FileName);
if (directory.Length == 0)
{
directory = AppDomain.CurrentDomain.BaseDirectory;
}
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
using (FileStream fileStream = new
FileStream(flatFileSinkData.FileName,
FileMode.Append,
FileAccess.Write, FileShare.ReadWrite))
{
using (StreamWriter writer = new StreamWriter(fileStream))
{
lock (syncObject)
{
if (flatFileSinkData.Header.Length > 0)
{
writer.WriteLine(flatFileSinkData.Header);
}
writer.WriteLine(FormatEntry(logEntry));
if (flatFileSinkData.Footer.Length > 0)
{
writer.WriteLine(flatFileSinkData.Footer);
}

writer.Flush();
}
}
}
}

You see if the filename is short, directory variable is set from current
appDomain base directory whish is perfect but it is not passed to FileStream.
I think the real problem is the FileStream class which stupidly opens the
file to the location openfile dialog last pointed.
AddThis Social Bookmark Button