//******************************************************************************************************
// LogSubscriber.cs - Gbtc
//
// Copyright © 2016, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain a copy of the License at:
//
// http://www.opensource.org/licenses/eclipse-1.0.php
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 10/24/2016 - Steven E. Chisholm
// Generated original version of source code.
//
//
//******************************************************************************************************
using System;
using System.Reflection;
namespace GSF.Diagnostics
{
///
/// Subscribes to log events.
///
public sealed class LogSubscriber : IDisposable
{
private readonly LogSubscriberInternal m_subscriber;
///
/// Event handler for the logs that are raised.
///
///
/// Any exceptions generated by this callback will be ignored.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1009:DeclareEventHandlersCorrectly")]
public event NewLogMessageEventHandler NewLogMessage
{
add
{
m_subscriber.NewLogMessage += value;
}
remove
{
m_subscriber.NewLogMessage -= value;
}
}
///
/// Creates a
///
internal LogSubscriber(LogSubscriberInternal subscriber)
{
m_subscriber = subscriber;
}
///
/// Subscribes to all publishers with the specified verbose level.
///
public void SubscribeToAll(VerboseLevel level)
{
m_subscriber.Subscribe(PublisherFilter.CreateUniversal(), MessageAttributeFilter.Create(level), false);
}
///
/// Subscribes to the publisher of the specified type with the specified verbose level.
///
public void SubscribeToType(Type type, VerboseLevel level)
{
if (type == null)
throw new ArgumentNullException(nameof(type));
m_subscriber.Subscribe(PublisherFilter.CreateType(type), MessageAttributeFilter.Create(level), false);
}
///
/// Subscribes to the publisher of the specified type expression with the specified verbose level.
///
/// An expression of the name of a type. Must include a * or ? to be considered an expression.
/// The level
public void SubscribeToType(string typeExpression, VerboseLevel level)
{
if (typeExpression == null)
throw new ArgumentNullException(nameof(typeExpression));
m_subscriber.Subscribe(PublisherFilter.CreateType(typeExpression), MessageAttributeFilter.Create(level), false);
}
///
/// Subscribes to the publisher of the specified assembly with the specified verbose level.
///
public void SubscribeToAssembly(Assembly assembly, VerboseLevel level)
{
if (assembly == null)
throw new ArgumentNullException(nameof(assembly));
m_subscriber.Subscribe(PublisherFilter.CreateAssembly(assembly), MessageAttributeFilter.Create(level), false);
}
///
/// Subscribes to the publisher of the specified assembly with the specified verbose level.
///
/// /// An expression of the name of an assembly. Must include a * or ? to be considered an expression.
/// The level
public void SubscribeToAssembly(string assemblyExpression, VerboseLevel level)
{
if (assemblyExpression == null)
throw new ArgumentNullException(nameof(assemblyExpression));
m_subscriber.Subscribe(PublisherFilter.CreateAssembly(assemblyExpression), MessageAttributeFilter.Create(level), false);
}
///
/// Ignore all messages of this verbose level.
///
public void IgnoreAll(VerboseLevel level)
{
m_subscriber.Subscribe(PublisherFilter.CreateUniversal(), MessageAttributeFilter.Create(level), true);
}
///
/// Ignore all messages of this verbose level.
///
public void IgnoreType(Type type, VerboseLevel level)
{
if (type == null)
throw new ArgumentNullException(nameof(type));
m_subscriber.Subscribe(PublisherFilter.CreateType(type), MessageAttributeFilter.Create(level), true);
}
///
/// Ignore all messages of this verbose level.
///
public void IgnoreType(string typeExpression, VerboseLevel level)
{
if (typeExpression == null)
throw new ArgumentNullException(nameof(typeExpression));
m_subscriber.Subscribe(PublisherFilter.CreateType(typeExpression), MessageAttributeFilter.Create(level), true);
}
///
/// Ignore all messages of this verbose level.
///
public void IgnoreAssembly(Assembly assembly, VerboseLevel level)
{
if (assembly == null)
throw new ArgumentNullException(nameof(assembly));
m_subscriber.Subscribe(PublisherFilter.CreateAssembly(assembly), MessageAttributeFilter.Create(level), true);
}
///
/// Ignore all messages of this verbose level.
///
public void IgnoreAssembly(string assemblyExpression, VerboseLevel level)
{
if (assemblyExpression == null)
throw new ArgumentNullException(nameof(assemblyExpression));
m_subscriber.Subscribe(PublisherFilter.CreateAssembly(assemblyExpression), MessageAttributeFilter.Create(level), true);
}
///
/// Clears all subscriptions
///
public void Clear()
{
m_subscriber.Clear();
}
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
/// 2
public void Dispose()
{
m_subscriber.Dispose();
}
}
}