SLAB file writer locking files

Topics: Semantic Logging Application Block
Nov 18, 2013 at 6:41 PM
I'm writing a program to parse and display log files created with the SLAB jsonformatter, and I'm running into a problem because the current log file seems to always be locked by the process being logged. Which makes sense for fast writes, but makes it difficult to show diagnostics.

I don't have access to the web server where the process is running, so my process so far is to use the SLAB to write log files to a directory I can see from other machines, and the run a log viewer there. Right now I have to stop the web service to free up the file.

Is there any way around this?
Nov 19, 2013 at 12:17 PM
I think you should be able to read the file. This is the code I use locally:
    string fileName = @"C:\My-Etw-Service\MyEventSource.log";

    using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
    using (var sr = new StreamReader(fs))
        while (!sr.EndOfStream)
            // Write out data or transfer somewhere else

Randy Levy
Enterprise Library support engineer
Support How-to