<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.dotnetzone.gr:443/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Πρώτα Βήματα - Γλώσσες προγραμματισμού</title><link>https://www.dotnetzone.gr:443/cs/forums/74/ShowForum.aspx</link><description>Τα πρώτα βήματα στις γλώσσες VB6, VB.NET, και C#</description><dc:language>el</dc:language><generator>CommunityServer 2.1 SP3 (Build: 20423.1)</generator><item><title>Απ:Πρόβλημα με την χρήση μιας function</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/24557.aspx</link><pubDate>Tue, 06 Feb 2007 01:25:29 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:24557</guid><dc:creator>dtakis</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/24557.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=74&amp;PostID=24557</wfw:commentRss><description>&lt;P&gt;Ποια είναι η χρήση της debug.writeline() όταν τρέχουμε service μπορούμε να δούμε κάπου το Output? Πρέπει να το κάνω build στο φάκελο από τον οποίο θα τρέξει στο τέλος γιατί μέχρι τώρα κάνω copy για ευκολία σε άλλο φάκελο.&lt;/P&gt;</description></item><item><title>Απ:Πρόβλημα με την χρήση μιας function</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/24553.aspx</link><pubDate>Tue, 06 Feb 2007 00:47:50 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:24553</guid><dc:creator>dtakis</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/24553.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=74&amp;PostID=24553</wfw:commentRss><description>ok! Κοιτάω και για τον event logger των Windows</description></item><item><title>Απ:Πρόβλημα με την χρήση μιας function</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/24550.aspx</link><pubDate>Tue, 06 Feb 2007 00:22:46 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:24550</guid><dc:creator>Dimitris Papadimitriou</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/24550.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=74&amp;PostID=24550</wfw:commentRss><description>&lt;p&gt;Ίσως είναι ο χειρότερος τρόπος που μπορεί να βρεις για να κάνεις log κάτι...!&lt;/p&gt;&lt;p&gt;Κατά τα άλλα βάλε ένα static πριν το &lt;span style="font-weight:normal;font-size:11px;color:black;font-family:Courier New;background-color:transparent;"&gt;void LogMessageToFile.&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Συμβουλή!!! Ψάξε να βρεις άλλο μηχανισμό για log!&amp;nbsp;&lt;/p&gt;</description></item><item><title>Πρόβλημα με την χρήση μιας function</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/24548.aspx</link><pubDate>Tue, 06 Feb 2007 00:15:12 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:24548</guid><dc:creator>dtakis</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/24548.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=74&amp;PostID=24548</wfw:commentRss><description>&lt;P&gt;Χρησιμοποιώ τον debug logger που διάβασα στο &lt;A href="http://blogs.msdn.com/csharpfaq/archive/2006/03/27/562555.aspx"&gt;http://blogs.msdn.com/csharpfaq/archive/2006/03/27/562555.aspx&lt;/A&gt;&amp;nbsp;που δίνει τον κώδικα&lt;/P&gt;
&lt;P&gt;using System.IO;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:black;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;using&lt;/SPAN&gt; System.IO;&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;string&lt;/SPAN&gt; GetTempPath()&lt;BR&gt;{&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;string&lt;/SPAN&gt; path &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; System.Environment.GetEnvironmentVariable(&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:#666666;FONT-FAMILY:Courier New;BACKGROUND-COLOR:#e4e4e4;"&gt;"TEMP"&lt;/SPAN&gt;);&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;if&lt;/SPAN&gt; (!path.EndsWith(&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:#666666;FONT-FAMILY:Courier New;BACKGROUND-COLOR:#e4e4e4;"&gt;"\\"&lt;/SPAN&gt;)) path += &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:#666666;FONT-FAMILY:Courier New;BACKGROUND-COLOR:#e4e4e4;"&gt;"\\"&lt;/SPAN&gt;;&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;return&lt;/SPAN&gt; path;&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;public&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;void&lt;/SPAN&gt; LogMessageToFile(&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;string&lt;/SPAN&gt; msg)&lt;BR&gt;{&lt;BR&gt;System.IO.StreamWriter sw &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; System.IO.File.AppendText(GetTempPath() &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;+&lt;/SPAN&gt; &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:#666666;FONT-FAMILY:Courier New;BACKGROUND-COLOR:#e4e4e4;"&gt;"My Log File.txt"&lt;/SPAN&gt;);&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;try&lt;/SPAN&gt;&lt;BR&gt;{&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;string&lt;/SPAN&gt; logLine &lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:red;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;=&lt;/SPAN&gt; System.String.Format(&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:#666666;FONT-FAMILY:Courier New;BACKGROUND-COLOR:#e4e4e4;"&gt;"{0:G}: {1}."&lt;/SPAN&gt;, System.DateTime.Now, msg);&lt;BR&gt;sw.WriteLine(logLine);&lt;BR&gt;}&lt;BR&gt;&lt;SPAN style="FONT-WEIGHT:normal;FONT-SIZE:11px;COLOR:blue;FONT-FAMILY:Courier New;BACKGROUND-COLOR:transparent;"&gt;finally&lt;/SPAN&gt;&lt;BR&gt;{&lt;BR&gt;sw.Close();&lt;BR&gt;}&lt;BR&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;και &lt;/P&gt;
&lt;P&gt;μπορούμε να το χρησιμοποιήσουμε παντού όπως και γίνεται στο OnStart ή στο OnStop καλώντας το ως: LogMessageToFile("Service Started from user");&lt;/P&gt;
&lt;P&gt;αλλά αν την χρησιμοποιήσω στην main ή στην static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)&amp;nbsp; οπότε και παίρνω:&lt;/P&gt;
&lt;P&gt;An object reference is required for the nonstatic field, method, or property 'TestService.Service1.LogMessageToFile(string)'&lt;/P&gt;
&lt;P&gt;Γνωρίζει κάποιος τι συμβαίνει ώστε να μπορώ να καλώ γενικά την function αυτή ή οποιαδήποτε άλλη μπορεί να χρειαστώ χωρίς να παίρνω αυτό το λάθος;&lt;/P&gt;
&lt;P&gt;Ευχαριστώ εκ των προτέρων&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description></item></channel></rss>