Let's start by the context !
At my job, I have been asked to add some log functionality to my project, a web app in ASP.NET.
What I thought is that well, I could have do it just for my project, but that's not very useful! So I want to create a DLL that can be used in others projects (webapps or windows apps).
So I planned these functionalities:
XML File for configuration : LogLevel of the file, location of the file, time for keeping it, max size before writing in a new log file. For example I can have a log file where will be written only ERROR and CRITICAL logs and another file where will be written INFO and WARNING LOGS.
- Ability to log for a web app or for a win app
But here is the problems, I'm thinking of differents things that can go wrong and I wanted to be sure of what I do before developping it.
First of all, I will have to detect if it's a web application or a windows application. I have find some things that can be helpful like this one
Then I'm thinking about how logs will be written, each time I will write a line of log, I will have to open and close my file. I feel like it's something very greedy in performances. Am I wrong ? Is there any other way to do it ?
It should also be pointed out that there could be a problem when logging from both web applications or a multi-threaded windows applications. Another issue is that the log method could be called twice (2 times) at once, which will then create a problem of simultaneous access for the log file. What is the best way to deal with these issues?
At last, I wonder if you see any other things that can be a problem for this kind of dll ?
Thanks for your help ! :)