473,378 Members | 1,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

One DLL writes to single file and used by multiple application

Hi All,

I am facing one problem. I have one DLL called LogManagement which has
ability to write to ExceptionLog and EventLog File. Both are separate file
locate in Logs Diectory. I have two windows service application and one
windows application which call the LogManagement DLL to write to log file.

I made the object of LogManagement as Singleton but when I run single
application, It runs perfect, but when I run

multiple application then It raises error. I can't debug because It's a
windows service but I know the

problem is EACH application is creating its own Object, I don't want to
create the object each time Because when I am initializing object I am also
checking that both the file exist or not ? If does not exist then create a
new file on same location. When file created one windows service starting
using the file to write event logs.
Aug 7 '06 #1
6 2250
One option would be to:
a: guard all file access by a global mutex
b: only hold the file (and mutex) open when actively writing (or creating)

This should allow bboth processes independent access to the file... you
could also use remoting to ensure that all writing goes through a single
process, but that is probably more brittle.

Marc
Aug 7 '06 #2
Hi,

"kumar_anil_gaya_India" <ku****************@discussions.microsoft.comwro te
in message news:54**********************************@microsof t.com...
Hi All,

I am facing one problem. I have one DLL called LogManagement which has
ability to write to ExceptionLog and EventLog File. Both are separate
file
locate in Logs Diectory. I have two windows service application and one
windows application which call the LogManagement DLL to write to log file.

I made the object of LogManagement as Singleton but when I run single
application, It runs perfect, but when I run

multiple application then It raises error.
Each app will have a copy of the dll so you will have three objetcs, one in
each program.
I can't debug because It's a
windows service
You can debug a win service, just attach the debugger to the process. (from
the debug menu)
There are several ways to solve this, the easiest is to create a new event
Log, one only used by your apps. doing this you do not have to take care of
concurrency problems.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 7 '06 #3
Hi Machine,
My requirement is to write to single file, my client is saying that we need
a single to manage all processes. We have windows service and windows
application which has some out put to write to same txt file. Every
application is using the same file. Basically One DLL is handling the writing
process. Ever application is using singleton object which is defined in the
DLL. But When I get the instance it creates new object every time in every
application.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

"kumar_anil_gaya_India" <ku****************@discussions.microsoft.comwro te
in message news:54**********************************@microsof t.com...
Hi All,

I am facing one problem. I have one DLL called LogManagement which has
ability to write to ExceptionLog and EventLog File. Both are separate
file
locate in Logs Diectory. I have two windows service application and one
windows application which call the LogManagement DLL to write to log file.

I made the object of LogManagement as Singleton but when I run single
application, It runs perfect, but when I run

multiple application then It raises error.

Each app will have a copy of the dll so you will have three objetcs, one in
each program.
I can't debug because It's a
windows service

You can debug a win service, just attach the debugger to the process. (from
the debug menu)
There are several ways to solve this, the easiest is to create a new event
Log, one only used by your apps. doing this you do not have to take care of
concurrency problems.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 7 '06 #4
Yes; that will happen. .Net singletons are scoped by their AppDomain, so
each process will get their own, separate instances that are ignorant of
eachother. Hence the need for a mutex, IPC, remoting or similar.

Marc
Aug 7 '06 #5
You can debug a windows service by attaching the debugger via the Debug
| Processes menu item. I recommend setting up the application to run
in two different modes: 1) Windows service and 2) Interactive
application. It's easier to debug when the application is running in
an interactive environment. If you don't want to take the time to get
that setup then there is a simple trick you can use.

public static void Main()
{
if (System.Diagnostics.Debugger.IsAttached)
{
// Run it as an interactive application.
Service1 service = new Service1();
service.OnStart(null);
Thread.CurrentThread.Join();
}
else
{
// Run it as a service application.
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}
}

There are several variations on this theme including the use of
conditional compilation.

Brian

kumar_anil_gaya_India wrote:
Hi All,

I am facing one problem. I have one DLL called LogManagement which has
ability to write to ExceptionLog and EventLog File. Both are separate file
locate in Logs Diectory. I have two windows service application and one
windows application which call the LogManagement DLL to write to log file.

I made the object of LogManagement as Singleton but when I run single
application, It runs perfect, but when I run

multiple application then It raises error. I can't debug because It's a
windows service but I know the

problem is EACH application is creating its own Object, I don't want to
create the object each time Because when I am initializing object I am also
checking that both the file exist or not ? If does not exist then create a
new file on same location. When file created one windows service starting
using the file to write event logs.
Aug 7 '06 #6
Hi,

I do not know if it was you or somebody else from your team, but if you look
for a thread named "sharing data in dlls" you will see a post there where I
gave a possible solution to this
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"kumar_anil_gaya_India" <ku****************@discussions.microsoft.comwro te
in message news:C0**********************************@microsof t.com...
Hi Machine,
My requirement is to write to single file, my client is saying that we
need
a single to manage all processes. We have windows service and windows
application which has some out put to write to same txt file. Every
application is using the same file. Basically One DLL is handling the
writing
process. Ever application is using singleton object which is defined in
the
DLL. But When I get the instance it creates new object every time in every
application.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
>Hi,

"kumar_anil_gaya_India" <ku****************@discussions.microsoft.com>
wrote
in message news:54**********************************@microsof t.com...
Hi All,

I am facing one problem. I have one DLL called LogManagement which has
ability to write to ExceptionLog and EventLog File. Both are separate
file
locate in Logs Diectory. I have two windows service application and
one
windows application which call the LogManagement DLL to write to log
file.

I made the object of LogManagement as Singleton but when I run single
application, It runs perfect, but when I run

multiple application then It raises error.

Each app will have a copy of the dll so you will have three objetcs, one
in
each program.
I can't debug because It's a
windows service

You can debug a win service, just attach the debugger to the process.
(from
the debug menu)
There are several ways to solve this, the easiest is to create a new
event
Log, one only used by your apps. doing this you do not have to take care
of
concurrency problems.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Aug 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Craig Ringer | last post by:
Hi folks I'm a bit of a newbie here, though I've tried to appropriately research this issue before posting. I've found a lot of questions, a few answers that don't really answer quite what I'm...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
5
by: BPearson | last post by:
Hello I would like to have several sites share a single web.config file. To accomplish this, I would point the root of these sites to the same folder. Is there any reason why I might not want to...
7
by: jsale | last post by:
I have made an ASP.NET web application that connects to SQL Server, reading and writing data using classes. I was recommended to use session objects to store the data per user, because each user...
3
by: Carl Johansen | last post by:
I have a big ASP website (used by several thousand car dealers) that is a collection of lots of small and medium-sized applications. Now I want to start adding ASP.NET applications to it. I have...
3
by: CD | last post by:
An application is logging faxes sent in SQL2000 image column type. I have found code on the net but what it is doing is prompting to save to local which is fine for single page image. Not good...
3
by: Claudio Pacciarini | last post by:
Hi everyone, I have a question about .NET code sharing and reuse, and also about application design best practices / guidelines. Currently, we have many different .NET projects in source...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
2
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, Sorry for the long-winded dissertation - but, I have an application where I need to write text to a rich text box using a common method, callable from anywhere in my application. The...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.