Or A
Or A

Reputation: 1789

Microsoft Enterprise Logging Application Block - Reading Log File

I'm using MS logging application block for logging my application event into a file called app-trace.log which located on the c:\temp folder.

I'm trying to find the best way to read this file at runtime and display it when the user asks for it.

I have 2 issues:

  1. It seems that this kind of feature is not supported by the framework, hence I have to write this reader myself. Am I missing something here? Is there any better way of getting this data (w/o buffering it in the memory or saving it into another file)?

  2. If I'm taking the only alternative left for me, and implementing the reader myself, when I'm trying to do:

    System.IO.FileStream fs = new System.IO.FileStream(@"c:\temp\app-trace.log", FileMode.Open, FileAccess.Read);

    I'm getting "File being used by another process c#". Probably the file is locked by the application block. Is there any way to access and read it anyhow?

Upvotes: 3

Views: 1310

Answers (1)

Randy Levy
Randy Levy

Reputation: 22655

You are correct that Enterprise Library does not support this.

If you must retrieve the data from file then you should be able to do it by using the following:

FileStream fs = new FileStream(@"c:\trace.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);


I'm curious why the users need access to the log files? Is it for support? If this is a server application, then I would probably seriously consider logging to a database and then retrieving the data from the database when the user wants to view the log information.

Upvotes: 2

Related Questions