Microsoft Enterprise Logging Application Block - reading a log file

I use the MS logging application block to register my application in a file called application-trace.log, which is located in the c: \ temp folder.

I am trying to find a better way to read this file at runtime and display it when the user requests it.

I have 2 questions:

  • It seems that this function is not supported by the framework, so I have to write this reader myself. Am I missing something? Is there a better way to get this data (without buffering in memory or saving it to another file)?

  • If I take the only alternative left for me and introduce the reader myself when I try to do:

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

    I get "File Used by Another C # Process". The file is probably locked by the application block. Is there any way to access and read it anyway?

+3
source share
1 answer

You are correct that the Enterprise Library does not support this.

If you must retrieve data from a file, you must do this using the following:

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


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

+2
source

Source: https://habr.com/ru/post/1726838/


All Articles