Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TraceContext.cs « Diagnostics « Composition « ComponentModel « System « UnitTestFramework « Tests « System.ComponentModel.Composition « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 57486c71b2989472e58bd8417a35c9871f45355f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
#if !SILVERLIGHT

using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;

namespace System.ComponentModel.Composition.Diagnostics
{
    public partial class TraceContext : IDisposable
    {
        private readonly SourceLevels _previousLevel = TraceSourceTraceWriter.Source.Switch.Level;
        private readonly TraceContextTraceListener _listener = new TraceContextTraceListener();

        public TraceContext(SourceLevels level)
        {
            TraceSourceTraceWriter.Source.Switch.Level = level;
            TraceSourceTraceWriter.Source.Listeners.Add(_listener);
        }

        [CLSCompliant(false)]
        public TraceEventDetails LastTraceEvent
        {
            get { return _listener.TraceEvents.LastOrDefault(); }
        }

        [CLSCompliant(false)]
        public IList<TraceEventDetails> TraceEvents
        {
            get { return _listener.TraceEvents; }
        }

        public void Dispose()
        {
            TraceSourceTraceWriter.Source.Listeners.Remove(_listener);
            TraceSourceTraceWriter.Source.Switch.Level = _previousLevel;            
        }
    }
}

#endif