CSharpTest.Net
Start Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Logging Assembly > (Global) Namespace > Log Class : Start Method

format
args

Glossary Item Box

Pushes a string into the trace stack so that log messages appear with the 'context' set to the information provided. The operation named should be performed by the current thread and the IDisposable object returned should be disposed when the operation completes.

Syntax

Visual Basic (Declaration) 
Public Shared Function Start( _
   ByVal format As String, _
   ByVal ParamArray args() As Object _
) As IDisposable
C# 
public static IDisposable Start( 
   string format,
   params object[] args
)

Parameters

format
args

Return Value

An IDisposable object that should be destroyed by calling the Dispose() method when the activity is complete.

Example

Log/Test/ThreadedLogTest.cs

C#Copy Code
Log.LogWrite += new LogEventHandler(Block_LogWrite);
try
{
    using (Log.Start("Blocking Test"))
    {
        //the start above should already get us in a blocked state:
        Assert.IsTrue(_isBlocked.WaitOne(300, false));

        //regaurdless, we should still get the first message
        EventData msg = NextMessage;
        Assert.AreEqual("Start Blocking Test", msg.Message);

        //Now let's just go nuts on the logger...
        for (int i = 0; i < 100; i++)
            Log.Write("Buffering at {0}%.", i);

        Thread.Sleep(100);
        Assert.AreEqual(0, _lastMessages.Count);
        _releaseBlock.Set();
        Thread.Sleep(100);
        Assert.IsFalse(_isBlocked.WaitOne(0, false));

        for (int i = 0; i < 100; i++)
            Assert.IsTrue(NextMessage.Message.StartsWith("Buffering at"));
    }
}
finally
{
    Log.LogWrite -= new LogEventHandler(Block_LogWrite);
}
VB.NETCopy Code
Log.LogWrite += New LogEventHandler(Block_LogWrite)
Try
    Using Log.Start("Blocking Test")
        'the start above should already get us in a blocked state:
        Assert.IsTrue(_isBlocked.WaitOne(300, False))

        'regaurdless, we should still get the first message
        Dim msg As EventData = NextMessage
        Assert.AreEqual("Start Blocking Test", msg.Message)

        'Now let's just go nuts on the logger...
        Dim i As Integer = 0
        While i < 100
            Log.Write("Buffering at {0}%.", i)
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While

        Thread.Sleep(100)
        Assert.AreEqual(0, _lastMessages.Count)
        _releaseBlock.[Set]()
        Thread.Sleep(100)
        Assert.IsFalse(_isBlocked.WaitOne(0, False))

        Dim i As Integer = 0
        While i < 100
            Assert.IsTrue(NextMessage.Message.StartsWith("Buffering at"))
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While
    End Using
Finally
    Log.LogWrite -= New LogEventHandler(Block_LogWrite)
End Try

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Reference

Log Class
Log Members

Source Code

Log/Log.cs

Generated with Document! X 2011 by Innovasys