1

I am trying to receive the last line of a message inserted into my log file (using Spring.NET Common Logging). My first step is to retrieve the name of the file which is a little tricker than expected as I cant find the relevant properties/cast for this.

I've found a few articles of how to retrieve the filename given the log4net file reader but nothing starting from the Spring.NET Common Logging class.

After I have received the filename, I will use a reverse file reader to retrieve the last name. Wondering peoples thoughts about reading in the file whilst it's potentially being written to by Common Logging / log4net?

enter image description here

1 Answer 1

1

You should be able to open the file for reading while its still open for writing by the logging infrastructure, but I'm a bit worried about your plans to read the "last" line. Between the point where you discover you need to open the file and the point where you manage to open the file to read it something else can write an entry to the log file, making it potentially difficult for you to get the line you want just by assuming its the 'last' line in the log.

Am I correct in assuming that this is a kind of way to respond to some error condition and then acquire the correlated log entries related to that error? If so, I'd recommend against gathering this info from the log file by reading the 'last' line and instead recommend that you parse the file searching for the right log entry (e.g., by date/time or some other info rather than 'last').

Otherwise, you're probably going to get the right log entry back in simplistic testing scenarios but not at all in a production system under any kind of real parallel load. Just my 2-cents here...

Sign up to request clarification or add additional context in comments.

1 Comment

it's not actually error conditions. they are logged messages which i'll be using log4net to log, and then i want to replay the last message and similar functions by reading the file back in. nothing should be stored in state memory. you say use the logging infrastructure to get the filename, that was my question HOW do I get it as there are no clear properties.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.