nighttrain's Profile User Rating: -----

Reputation: 8 Worker
Group:
Active Members
Active Posts:
357 (0.24 per day)
Joined:
22-September 10
Profile Views:
4,740
Last Active:
User is offline Yesterday, 05:09 AM
Currently:
Offline

Previous Fields

Country:
PL
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Volkswagen
Dream Kudos:
0
Icon   nighttrain still drilling

Posts I've Made

  1. In Topic: Passing Data Between Forms

    Posted 26 Oct 2014

    could you also describe situation when we have tw completly separated forms how to execute some method inside second form when first form raises an event ?
  2. In Topic: Logger class again

    Posted 20 Oct 2014

    thanks tlhIn`toq. I implemented and added something from myself. Anyway don't you think right now every class have to implement event and method which will fire it up? Do we duplicating code? Maybe its better to prepare some generic class which would provide same event eventually delegate type and method which would raise it so every class could inherit it. What do you think?
  3. In Topic: Logger class again

    Posted 19 Oct 2014

    the problem is couple of classes are not listening to event because the event will be raised from classes directly. I would be able to develop it if the Logger class would raise event and then all classes would listen to in and do some react. Here situation is different because all classes want to log so they would raise some event right? So how should this be solved in this way?
  4. In Topic: Logger class using event/delegate way

    Posted 19 Oct 2014

    I started to preparing something like this below. As you can see i have class 'SomeClass' inside i would like to do log e.g in method 'SomeMethod' and 'SomeMethod2'. This is just example class i have it more. How i can correct my code to do it. This is what i did so far:

    Imports System.IO
    
    Public Delegate Sub DoLogEventHandler(sender As Object, e As DoLogEventArgs)
    
    Class SomeClass
        Public Event DoLog As DoLogEventHandler
    
        Protected Overridable Sub OnDoLog(e As DoLogEventArgs)
            RaiseEvent DoLog(Me, e)
        End Sub
    
        Public Sub DoMyLog(filename As String, fullPath As String, Message As String)
            Dim e As New DoLogEventArgs(filename, fullPath, Message)
            OnDoLog(e)
        End Sub
    
        Public Sub SomeMethod()
            'some code
            'some code
            'e.g here i would like to make a log ... <------------------------------------------
        End Sub
    
        Public Sub SomeMethod2()
            'some code
            'some code
            'e.g here i would like to make a log ... <------------------------------------------
        End Sub
    End Class
    
    Public Class DoLogEventArgs
        Public filename As String
        Public fullPath As String
        Public Message As String
    
        Public Sub New(_filename As String, _fullPath As String, _Message As String)
            filename = _filename
            fullPath = _fullPath
            Message = _Message
        End Sub
    End Class
    
    '---------------------------------------------------------------------------------------------------------------------
    Class Logger
        Public Sub New(anyclass As SomeClass)    '<--------wrong because only one specific class can be put here...
            AddHandler anyclass .DoLog, AddressOf CallLogger
        End Sub
    
        Private Sub CallLogger(sender As Object, e As DoLogEventArgs)
            'Console.WriteLine("Sender of event: " & sender.ToString())
            If File.Exists(e.fullPath & e.filename) Then
                Using w As TextWriter = File.AppendText((e.fullPath & e.filename))
                    w.WriteLine(DateTime.Now + "> " & e.Message)
                    w.Flush()
                End Using
            Else
                Using w As TextWriter = File.CreateText((e.fullPath & e.filename))
                    w.WriteLine(DateTime.Now + "> " & e.Message)
                    w.Flush()
                End Using
            End If
        End Sub
    End Class
    
    
  5. In Topic: Logger class using event/delegate way

    Posted 18 Oct 2014

    Hi Hawks, what i want to have is Logger class to log to some file which i would like to call from diffrent out classes. Could you help me to correct Logger class and show how to use it?

My Information

Member Title:
D.I.C Regular
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Poland
Full Name:
Bob
Years Programming:
4
Programming Languages:
VB,NET, C++, C#, PHP, HTML, JS, CSS, Pascal,

Contact Information

E-mail:
Click here to e-mail me
ICQ:
ICQ  637172526

Friends

Comments

Page 1 of 1
  1. Photo

    FlashM Icon

    24 Sep 2010 - 14:17
    no problem... you're welcome anytime...
Page 1 of 1