- Code.zip
- Code
- Global
- EncodeFirst.Core
- Attributes
- bin
- Debug
- DI.Global.dll
- DataAccess
- EncodeFirst.Core.csproj
- EncodeFirst.Core.csproj.user
- Helpers
- Managers
- obj
- Properties
- Types
- DataModel
- Filters
- Include.sln
- Include.suo
- TestService
- EncodeFirst.TestService.BusinessObjects
- EncodeFirst.TestService.DataAccess
- EncodeFirst.TestService.Global
- bin
- Debug
- ConfigService.Cache.dll
- ConfigService.CacheDataContract.dll
- DI.Global.dll
- DI.TestService.BusinessObjects.dll
- DI.TestService.Global.dll
- EncodeFirst.TestService.Core.csproj
- Managers
- obj
- Properties
- UnitTest
- App.config
- bin
- Debug
- ConfigService.Cache.dll
- ConfigService.CacheDataContract.dll
- ConfigService.IConfigActions.dll
- ConfigService.RuntimeHostData.dll
- ConfigService.ServiceConfiguration.DALFactory.dll
- ConfigService.ServiceConfiguration.DataContract.dll
- ConfigService.ServiceConfiguration.IDAL.dll
- ConfigService.ServiceConfigurationContract.dll
- ConfigService.ServiceConfigurationHelper.dll
- ConfigService.ServiceConfigurationUtility.dll
- ConfigService.ServiceNodeCommunication.DataContract.dll
- ConfigService.ServiceNodeCommunicationContract.dll
- DI.TestService.BusinessRules.dll
- DataAccess
- obj
- Debug
- TempPE
- Properties
- UnitTest.csproj
- Scripts.zip
- Scripts
|
using System;
using System.Threading;
using System.Diagnostics;
using EncodeFirst.Core;
using EncodeFirst.Core.Managers;
namespace EncodeFirst.TestService.Core.Managers
{
public sealed class LogManager : ILogManager
{ //Here, encapsulate some Log Framework (NLog, Log4Net, ...)
static readonly LogManager _instance = new LogManager();
/// <summary>
/// Gets the instance of LogManager.
/// </summary>
/// <remarks></remarks>
public static LogManager Instance
{
get
{
return _instance;
}
}
LogManager()
{
}
/// <summary>
/// Writes the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <remarks></remarks>
public void Write(string message)
{
Write(message, EventLogEntryType.Information);
}
/// <summary>
/// Writes the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="ex">The ex.</param>
/// <remarks></remarks>
public void Write(string message, Exception ex)
{
Write(message, ex, EventLogEntryType.Error);
}
/// <summary>
/// Writes the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="logType">Type of the log.</param>
public void Write(string message, EventLogEntryType logType)
{
Write(message, null, logType);
}
/// <summary>
/// Writes the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="ex">The exception</param>
/// <param name="logType">Type of the log.</param>
public void Write(string message, Exception ex, EventLogEntryType logType)
{
Thread thread = new Thread(delegate()
{
try
{
if (message == null) message = string.Empty;
message += MessageHelper.GetExceptionMessages(ex);
//Write the message here, use some technology or framework (NLog, Log4Net, ...)
}
catch (Exception exc)
{ //if fail call the last option method to write the log
WriteOnLastOption(message, ex, exc);
}
});
thread.Start();
}
/// <summary>
/// Writes the on last option.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="originalEx">The original exception.</param>
/// <param name="ex">The current exception.</param>
public void WriteOnLastOption(string message, Exception originalEx, Exception ex)
{
Thread thread = new Thread(delegate()
{
//Last option to write the log, write on a file or EventLog
});
thread.Start();
}
}
}
|
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.