W
WingSiu
I am writing a Logging util for my ASP.NET application.
I am facing mulit process problem.
I developed a class LogFactory, and have a method called Get_Logger to
create a FileLogger, which will write text into a text file.
// sample code
FileLogger logger = LogFactory.Get_Logger();
logger.Log("Message here");
logger = null;
I read a lot of example that when we face the mulit process problem, we can
use the keyword "lock" to solve the problem
// example
File logger logger = LogFactory.Get_Logger();
lock (typeof (logger))
{
log.Log("Message here");
}
logger = null;
although a lot of article said that DONT use lock(typeof(logger)) because it
is a slow process and it will lock all objects, which in the same
application, and used in other process. However, I think in my case, I can
use typeof(logger) because I am try to write the message in a single text
file, no matter which process a instancing the logger object, I only need to
lock the text file, write text, release it and then other process repeat the
same step, right?
So my code is correct?? or any other better solution? Thanks
I am facing mulit process problem.
I developed a class LogFactory, and have a method called Get_Logger to
create a FileLogger, which will write text into a text file.
// sample code
FileLogger logger = LogFactory.Get_Logger();
logger.Log("Message here");
logger = null;
I read a lot of example that when we face the mulit process problem, we can
use the keyword "lock" to solve the problem
// example
File logger logger = LogFactory.Get_Logger();
lock (typeof (logger))
{
log.Log("Message here");
}
logger = null;
although a lot of article said that DONT use lock(typeof(logger)) because it
is a slow process and it will lock all objects, which in the same
application, and used in other process. However, I think in my case, I can
use typeof(logger) because I am try to write the message in a single text
file, no matter which process a instancing the logger object, I only need to
lock the text file, write text, release it and then other process repeat the
same step, right?
So my code is correct?? or any other better solution? Thanks