|
namespace BusinessAppMVVM.Web.Services
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using NLog;
using System.Configuration; //Add in namespace section
// TODO: Create methods containing your application logic.
[EnableClientAccess()]
//[RequiresAuthentication]
public class LoggingService : DomainService
{
private static readonly Logger Logger = LogManager.GetLogger("LoggingService");
[Invoke]
public string GetLogONOFFFlag()
{
string flag = ConfigurationManager.AppSettings.Get("IsEventLogOn");
return flag;
}
protected override void OnError(DomainServiceErrorInfo errorInfo)
{
//Log exception errorInfo.Error
LogException("Error in BriteDomainService RIA Service. ", errorInfo.ToString());
base.OnError(errorInfo);
}
[Invoke]
public void LogException(string errorCommentOrType, string Detail)
{
string errorMessage = String.Empty;
string strUser = string.Empty;
try
{
//Following code for getting user name will work only when ApplicationServices/authentication is set in connection string. I will cover it in next topic
if (this.ServiceContext.User != null)
if (this.ServiceContext.User.Identity != null)
strUser = this.ServiceContext.User.Identity.Name;
Detail = " [UserName: " + strUser + "] " + "Time: " + DateTime.Now.ToString() + " " + Detail;
}
catch (Exception ex)
{
Logger.Error("Logging Error: " + ex);
}
finally
{
errorMessage = errorCommentOrType + " - " + Detail;
switch (errorCommentOrType)
{
case "Fatal":
Logger.Fatal(errorMessage);
break;
case "Error":
Logger.Error(errorMessage);
break;
case "Warn":
Logger.Warn(errorMessage);
break;
case "Info":
Logger.Info(errorMessage);
break;
case "Debug":
Logger.Debug(errorMessage);
break;
case "Trace":
Logger.Trace(errorMessage);
break;
default:
Logger.Error(errorMessage);
break;
}
}
}
}
}
|
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.