My application is running in one server. Now i want to write the log details in "Event Log" of one of the REMOTE servers (to which I have accesss). Need C# code to do the job.
i'm not sure whether you can write directly to an Event Log on another computer ... even if you can, a better approach
may be to create a web service on the other computer and pass it the information that you want to log; since you probably already know how to write to the event log locally, you would have code in your web service then write to its "local" Event Log.
g.
TIMTOWTDI =. there is more than one way to do it
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
Log4Net sort of has this built in. You'd set up a service on the remote machine which implements the end points for either
RemotingAppender or
UdpAppender.
If the answer I provided is useful or informative please check the "answer" button.
Warning: Code is often uncompiled and possibly started life written on the back of a napkin. Beware typos.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
Have you considered using the features built in to the server event system to just forward the events to the desired central computer without writing any code or installing any third party tools? Google 'windows server event log forwarding' or start at
http://www.windowsecurity.com/articles/Accessing-Security-Logs-Remotely-Efficiently.html Of course, if you don't have appropriate OS versions (seems to be anything older than Windows XP can't forward events, earlier than Vista can't subscribe to events)
then you will need to use some external tools/roll your own.
If you don't write any code then there are no bugs and there is no maintenance burden.
Although this can be easily achieved writting a webservice, but my requirement is to accomplish it without it. Is it possible to code it in a way we log event in the same system?
This is a good article on event forwarding. But how this can be achieved in C#? I believe the stpes would be like:
1. Write the Event log in the same server where the application in running (application server).
2. Then the event will automatically be forwared to the remote server's Event log (which will require prior event log settings in the application server)
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
YugJMallik
Member
91 Points
71 Posts
Writing event log in remote machine – C#
Aug 10, 2012 12:37 PM|LINK
Hi,
My application is running in one server. Now i want to write the log details in "Event Log" of one of the REMOTE servers (to which I have accesss). Need C# code to do the job.
Thanks,
Yug
Yug
www.extreme-minds.com
gerrylowry
All-Star
20513 Points
5712 Posts
Re: Writing event log in remote machine – C#
Aug 10, 2012 12:54 PM|LINK
@ YugJMallik
i'm not sure whether you can write directly to an Event Log on another computer ... even if you can, a better approach may be to create a web service on the other computer and pass it the information that you want to log; since you probably already know how to write to the event log locally, you would have code in your web service then write to its "local" Event Log.
g.
TIMTOWTDI =. there is more than one way to do it
JeffreyABeck...
All-Star
16423 Points
3329 Posts
Re: Writing event log in remote machine – C#
Aug 10, 2012 03:59 PM|LINK
Log4Net sort of has this built in. You'd set up a service on the remote machine which implements the end points for either RemotingAppender or UdpAppender.
Warning: Code is often uncompiled and possibly started life written on the back of a napkin. Beware typos.
gerrylowry
All-Star
20513 Points
5712 Posts
Re: Writing event log in remote machine – C#
Aug 10, 2012 09:48 PM|LINK
@ JeffreyABecker
Hi Jeffrey ... are you saying that Log4Net will actually write "Event Log" style events to the Event Log on the remote computer?
i'm curious about this because apparently ELMAH does not do this:
http://stackoverflow.com/questions/1978555/log-errors-in-eventlog-using-elmah [last activity Jan 14 '10]
g.
http://stackoverflow.com/questions/5057674/what-is-the-difference-between-log4net-and-elmah
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx "EventLog Class"
Paul Linton
Star
13403 Points
2531 Posts
Re: Writing event log in remote machine – C#
Aug 11, 2012 02:12 AM|LINK
Have you considered using the features built in to the server event system to just forward the events to the desired central computer without writing any code or installing any third party tools? Google 'windows server event log forwarding' or start at http://www.windowsecurity.com/articles/Accessing-Security-Logs-Remotely-Efficiently.html Of course, if you don't have appropriate OS versions (seems to be anything older than Windows XP can't forward events, earlier than Vista can't subscribe to events) then you will need to use some external tools/roll your own.
If you don't write any code then there are no bugs and there is no maintenance burden.
YugJMallik
Member
91 Points
71 Posts
Re: Writing event log in remote machine – C#
Aug 13, 2012 05:58 AM|LINK
Gerrylowry,
Although this can be easily achieved writting a webservice, but my requirement is to accomplish it without it. Is it possible to code it in a way we log event in the same system?
Yug
www.extreme-minds.com
YugJMallik
Member
91 Points
71 Posts
Re: Writing event log in remote machine – C#
Aug 13, 2012 06:03 AM|LINK
@Paul,
This is a good article on event forwarding. But how this can be achieved in C#? I believe the stpes would be like:
1. Write the Event log in the same server where the application in running (application server).
2. Then the event will automatically be forwared to the remote server's Event log (which will require prior event log settings in the application server)
Yug
www.extreme-minds.com
Paul Linton
Star
13403 Points
2531 Posts
Re: Writing event log in remote machine – C#
Aug 13, 2012 06:05 AM|LINK
Correct. The C# code for step 2 would be
{ }No code - the most bug free and maintainable code of all!
You do have to follow the instructions to configure your servers correctly.
gerrylowry
All-Star
20513 Points
5712 Posts
Re: Writing event log in remote machine – C#
Aug 13, 2012 07:18 PM|LINK
@ YugJMallik
AFAIK, no, the Framework, and likely the Windows API do not support it ...
i could be wrong ...
you might want to try posting your requirements at stackoverflow.com,
and/or http://social.msdn.microsoft.com/Forums/en/category/visualcsharp
===> http://social.msdn.microsoft.com/Forums/en/csharpgeneral/threads
and/or other forums, including forums like http://social.technet.microsoft.com/Forums/en-us/categories/.
Yug, unfortunately, getting detailed information about this kind of request is not that easy AFAIK ...
... perhaps you might share with us why you "must" implement this in c#?
Also, Paul Linton's link http://www.windowsecurity.com/articles/Accessing-Security-Logs-Remotely-Efficiently.html should actually work for you ... zero code required ... you simply configure it:
look in the Event Viewer help for "Configure Computers to Forward and Collect Events" and/or check this link: http://technet.microsoft.com/en-us/library/cc748890.aspx.
g.