|
/***************************************************************************
Copyright 2008, Thoraxcentrum, Erasmus MC, Rotterdam, The Netherlands
Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Written by Maarten JB van Ettinger.
****************************************************************************/
using System;
using System.Diagnostics;
using System.Text;
using System.Threading;
namespace ECGtoPACS
{
public class ServiceLogger
{
private static ServiceLogger s_Instance;
private static Mutex s_Mutex = new Mutex();
public static ServiceLogger Instance
{
get
{
s_Mutex.WaitOne();
if (s_Instance == null)
{
s_Instance = new ServiceLogger();
}
s_Mutex.ReleaseMutex();
return s_Instance;
}
}
private Boolean m_bLoggingEnabled = false;
private EventLog m_Log = null;
private ServiceLogger()
{
}
~ServiceLogger()
{
}
public EventLog EventLogger
{
set
{
m_Log = value;
m_bLoggingEnabled = m_Log != null;
}
}
public void Log(String message, EventLogEntryType type)
{
if (m_bLoggingEnabled)
m_Log.WriteEntry(message, type);
else
Console.Error.WriteLine("{0}: {1}", type.ToString(), message);
}
public void Log(String message)
{
if (m_bLoggingEnabled)
m_Log.WriteEntry(message, EventLogEntryType.Information);
else
Console.Error.WriteLine("{0}: {1}", EventLogEntryType.Information.ToString(), message);
}
public void Log(Exception ex)
{
if (m_bLoggingEnabled)
m_Log.WriteEntry(ex.Message, EventLogEntryType.Error);
else
Console.Error.WriteLine("{0}: {1}", EventLogEntryType.Information.ToString(), ex.ToString());
}
public void Log(Exception ex, EventLogEntryType type)
{
if (m_bLoggingEnabled)
m_Log.WriteEntry(ex.Message, type);
else
Console.Error.WriteLine("{0}: {1}", type.ToString(), ex.ToString());
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.