RTC Forums
November 28, 2024, 07:18:57 AM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Help
Login
Register
RTC Forums
>
Subscription
>
Support
>
Writing to an exceptions log
Pages: [
1
]
« previous
next »
Print
Author
Topic: Writing to an exceptions log (Read 5764 times)
dpcroghan
RTC Expired
Posts: 17
Writing to an exceptions log
«
on:
October 09, 2013, 05:11:33 PM »
Danijel,
I have a question regarding RtcHttpServer when multithreading is true. I'd like to write any exceptions and connection errors to a text file. However, is this safe/possible if the server is multithreaded? Currently I have code like below in many of the event handlers, but what about problems that arise when the server is not in the main thread. Is there a way to log these. Forgive my lack of understanding about multithreading, I'm definitely in learning mode.
Thanks
procedure TForm2.RtcHttpServer1RequestNotAccepted(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
begin
Sender.Sync(RtcHttpServer1RequestNotAccepted);
end
else
begin
mmResult.Lines.Add('Request not accepted at ' + DateTimeToStr(now));
end;
end;
Logged
dpcroghan
RTC Expired
Posts: 17
Re: Writing to an exceptions log
«
Reply #1 on:
October 09, 2013, 05:23:14 PM »
I think I should also ask, what are the pros and cons to setting multithreading to true or false for this component? Perhaps you can direct me to a resource that discusses this.
Thanks for providing excellent support.
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: Writing to an exceptions log
«
Reply #2 on:
October 09, 2013, 07:26:44 PM »
You can use the "Log" and "XLog" procedures from the "rtcLog.pas" unit for writing log files. These procedures are thread-safe and work without the need to synchronize the code with the main thread.
When MultiThreaded=True, the RtcHttpServer component will be using a thread pool to execute its code and all events called by the component from background threads instead of doing it from the main thread. This allows the Server to process requests from multiple clients at the same time, without having to serialize them.
Best Regards,
Danijel Tkalcec
Logged
dpcroghan
RTC Expired
Posts: 17
Re: Writing to an exceptions log
«
Reply #3 on:
October 09, 2013, 08:54:46 PM »
Would you call StartLog() on FormCreate and StopLog on FormClose
or is it better to use StartLog() Log('Some message') StopLog() at each logging location?
Thanks.
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: Writing to an exceptions log
«
Reply #4 on:
October 09, 2013, 10:07:31 PM »
I would call StartLog in main units
initialization
section or in the Project file (DPR).
There is no need to call StopLog, unless you want to ignore calls to Logging functions.
Best Regards,
Danijel Tkalcec
Logged
dpcroghan
RTC Expired
Posts: 17
Re: Writing to an exceptions log
«
Reply #5 on:
October 09, 2013, 10:21:29 PM »
Thanks Danijel.
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Dashboard
-----------------------------
=> General
=> 3rd-Party
=> Quick Start
-----------------------------
Subscription
-----------------------------
=> Support
Loading...