Ejemplo n.º 1
0
        static void Main()
        {
            RadiusProgramMainFunctions
            .ProgramMain(
                "winems-evolution-processing",
                () =>
            {
                ApplicationState.LogFolder =
                    "log-folder"
                    .AppSetting()
                    .UseFolderOrDefault(
                        @"C:\Neurasoft\logs\WineMS\Evolution");

                Log4NetLoggingFactory.BindLog4Net(
                    Log4NetLoggingFactory.DefaultConfig(
                        ApplicationState.LogFolder,
                        "winems-evolution-log.txt"));
                CommonInitFunctions.Init();
            },
                () =>
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FrmMain());
            },
                exception => { exception.LogAndShowExceptionDialog(); },
                () => { });
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            RadiusProgramMainFunctions
            .ProgramMain(
                "winems-evolution-processing-cli",
                () =>
            {
                Log4NetLoggingFactory.BindLog4Net(
                    Log4NetLoggingFactory.DefaultConfig(
                        "log-folder".AppSetting()
                        .UseFolderOrDefault(
                            @"C:\Neurasoft\logs\WineMS\Evolution"),
                        "winems-evolution-log.txt"));
                CommonInitFunctions.Init();
            },
                () =>
            {
                ApplicationInformationFunctions.LogApplicationInformation(
                    ApplicationInformationFunctions.GetApplicationInformation());

                // TODO: add code to call transaction processing functions.
            },
                exception => { },
                () => { },
                RadiusProgramMainFunctions.FinallyPause.IfDebuggerAttached);
        }
        public WebSecurity(
            IContextProvider contextService
            , IApplicationConfiguration configurationRepository
            , ApplicationUserManager userManager
            , ApplicationSignInManager signInManager
            )
        {
            _configurationRepository = configurationRepository;
            _userManager             = userManager;
            _signInManager           = signInManager;

            try
            {
                var dbContextAsync = DataContextFactory.GetDataContextAsync();
                dbContextAsync.GetDatabase().Initialize(true);

                if (_loggingService == null)
                {
                    _loggingService = Log4NetLoggingFactory.GetLogger();
                }

                _unitOfWorkAsync = new UnitOfWork(dbContextAsync, new RowAuthPoliciesContainer(_cachedUserAuthorizationGrantsProvider));
                // UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(_dbContextAsync as DbContext));
            }
            catch (Exception ex)
            {
                FetchLoggerAndLog(ex);
            }
        }
 private void FetchLoggerAndLog(Exception ex)
 {
     if (_loggingService != null)
     {
         return;
     }
     _loggingService = Log4NetLoggingFactory.GetLogger();
     _loggingService.LogWarning(this, "IDisposable problem disposing", ex);
 }
        public void SendMail(string from, string to, string subject, string body)
        {
            var email = new StringBuilder();

            email.AppendLine($"To: {to}");
            email.AppendLine($"From: {from}");
            email.AppendLine($"Subject: {subject}");
            email.AppendLine($"Body: {body}");

            Log4NetLoggingFactory.GetLogger().LogInfo(this, email.ToString());
        }
Ejemplo n.º 6
0
        public void Dispose()
        {
            if (_uow != null)
            {
                try
                {
                }
                catch (Exception disposeException)
                {
                    Log4NetLoggingFactory.GetLogger().LogWarning(this, "IDisposable - problem disposing", disposeException);
                }
            }

            Disposed = true;
        }
Ejemplo n.º 7
0
        private void Append(LoggingEvent loggingEvent)
        {
            var request = new LogToDatabaseRequest();

            try
            {
                var dto = new LoggingEventDto
                {
                    Domain              = loggingEvent.Domain,
                    UserName            = loggingEvent.UserName,
                    TimeStamp           = loggingEvent.TimeStamp,
                    ThreadName          = loggingEvent.ThreadName,
                    RenderedMessage     = loggingEvent.RenderedMessage,
                    MessageObject       = loggingEvent.MessageObject,
                    LoggerName          = loggingEvent.LoggerName,
                    LocationInformation = loggingEvent.LocationInformation,
                    DisplayName         = loggingEvent.Level.DisplayName,
                    Identity            = loggingEvent.Identity,
                    Properties          = loggingEvent.GetProperties(),
                    ExceptionObject     = loggingEvent.ExceptionObject,
                    ExceptionString     = loggingEvent.GetExceptionString()
                };

                // send this string message to wcf service
                request.LoggingEventDto = dto;

                if (FakeList == null)
                {
                    FakeList = new List <LogToDatabaseRequest>();
                }

                FakeList.Add(request);
            }
            catch (Exception exc)
            {
                Log4NetLoggingFactory.GetLogger()
                .LogFatal(typeof(WcfAppenderService), "Append(LoggingEvent loggingEvent)", exc);
            }
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        /// <summary>
        ///     TODO: This should be encrypted due to possible sensitive data being transmitted (for logging purposes)...
        /// </summary>
        /// <param name="loggingEventDto"></param>
        /// <returns></returns>
        public int?LogToDatabase(LoggingEventData loggingEventDto)
        {
            int?retVal = -1;

            var myLog = loggingEventDto.ConvertToDbLog();

            try
            {
                _uow.RepositoryAsync <DbLog>().Insert(myLog);
                _uow.SaveChangesAsync();
                retVal = 1;
            }
            catch (Exception dbException)
            {
                myLog.ExceptionMessage +=
                    string.Format("		[ DB ] ====>		Db exception while saving exception: [ {0} ]   [ {1} ]",
                                  dbException.Message, dbException.InnerException);

                // Log to file...
                Log4NetLoggingFactory.GetLogger().LogWarning(this, myLog.ExceptionMessage, dbException, false);
            }

            return(retVal);
        }
        public static DbLog ConvertToDbLog(this LoggingEventData loggingEventDto)
        {
            const string replacementToken = "N/A";
            var          myLog            = new DbLog();

            try
            {
                #region Map LoggingEvent (Log4Net)

                myLog.ADUser       = loggingEventDto.Domain ?? replacementToken;
                myLog.CreatedDate  = loggingEventDto.TimeStamp;
                myLog.UserId       = 1;
                myLog.UserName     = loggingEventDto.UserName ?? replacementToken;
                myLog.TrackingNo   = replacementToken;
                myLog.Operation    = replacementToken;
                myLog.InputParams  = replacementToken;
                myLog.OutputParams = replacementToken;
                myLog.FileName     = replacementToken;
                // myLog.ErrorLevel = loggingEventDto.DisplayName ?? replacementToken;
                myLog.ModifiedDate        = loggingEventDto.TimeStamp;
                myLog.AbsoluteUrl         = replacementToken;
                myLog.ClientBrowser       = replacementToken;
                myLog.RemoteHost          = replacementToken;
                myLog.Path                = replacementToken;
                myLog.Query               = replacementToken;
                myLog.RequestId           = replacementToken;
                myLog.SessionId           = replacementToken;
                myLog.ExceptionType       = replacementToken;
                myLog.ExceptionMessage    = replacementToken;
                myLog.ExceptionStackTrace = replacementToken;
                // myLog.Message = loggingEventDto.RenderedMessage ?? replacementToken;
                myLog.AssemblyQualifiedName = replacementToken;
                myLog.Namespace             = replacementToken;
                myLog.LogSource             = replacementToken;

                #endregion

                #region Map Properties

                if (loggingEventDto.Properties["RefererUrl"] != null)
                {
                    var l = loggingEventDto.Properties["RefererUrl"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.AbsoluteUrl = l;
                    }
                }

                if (loggingEventDto.Properties["UserAgent"] != null)
                {
                    var l = loggingEventDto.Properties["UserAgent"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.ClientBrowser = l;
                    }
                }

                if (loggingEventDto.Properties["RemoteHost"] != null)
                {
                    var l = loggingEventDto.Properties["RemoteHost"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.RemoteHost = l;
                    }
                }

                if (loggingEventDto.Properties["Path"] != null)
                {
                    var l = loggingEventDto.Properties["Path"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.Path = l;
                    }
                }

                if (loggingEventDto.Properties["Query"] != null)
                {
                    var l = loggingEventDto.Properties["Query"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.Query = l;
                    }
                }

                if (loggingEventDto.Properties["RequestId"] != null)
                {
                    var l = loggingEventDto.Properties["RequestId"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.RequestId = l;
                    }
                }

                if (loggingEventDto.Properties["SessionId"] != null)
                {
                    var l = loggingEventDto.Properties["SessionId"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.SessionId = l;
                    }
                }

                if (loggingEventDto.Properties["ExceptionType"] != null)
                {
                    var l = loggingEventDto.Properties["ExceptionType"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.ExceptionType = l;
                    }
                }

                if (loggingEventDto.Properties["ExceptionMessage"] != null)
                {
                    var l = loggingEventDto.Properties["ExceptionMessage"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.ExceptionMessage = l;
                    }
                }

                if (loggingEventDto.Properties["ExceptionStackTrace"] != null)
                {
                    var l = loggingEventDto.Properties["ExceptionStackTrace"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.ExceptionStackTrace = l;
                    }
                }

                if (loggingEventDto.Properties["AssemblyQualifiedName"] != null)
                {
                    var l = loggingEventDto.Properties["AssemblyQualifiedName"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.AssemblyQualifiedName = l;
                    }
                }

                if (loggingEventDto.Properties["Namespace"] != null)
                {
                    var l = loggingEventDto.Properties["Namespace"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.Namespace = l;
                    }
                }

                if (loggingEventDto.Properties["LogSource"] != null)
                {
                    var l = loggingEventDto.Properties["LogSource"].ToString();
                    if (!string.IsNullOrEmpty(l))
                    {
                        myLog.LogSource = l;
                    }
                }


                // myLog.InnerExceptionMessage = loggingEventDto.Properties["InnerException.Message"].ToString();
                // myLog.InnerExceptionSource = loggingEventDto.Properties["InnerException.Source"].ToString();
                // myLog.InnerExceptionStackTrace = loggingEventDto.Properties["InnerException.StackTrace"].ToString();
                // myLog.InnerExceptionTargetSite = loggingEventDto.Properties["InnerException.TargetSite"].ToString();

                try
                {
                    //if (loggingEventDto.LocationInformation != null)
                    //{
                    //    if (loggingEventDto.LocationInformation.ClassName != null)
                    //        myLog.Method += loggingEventDto.LocationInformation.ClassName;

                    //    if (loggingEventDto.LocationInformation.FileName != null)
                    //        myLog.FileName += loggingEventDto.LocationInformation.FileName;

                    //    if (loggingEventDto.LocationInformation.FullInfo != null)
                    //        myLog.MethodName += loggingEventDto.LocationInformation.MethodName;

                    //    if (loggingEventDto.LocationInformation.LineNumber != null)
                    //        myLog.LineNo += loggingEventDto.LocationInformation.LineNumber;

                    //    if (loggingEventDto.LocationInformation.MethodName != null)
                    //        myLog.MethodName += loggingEventDto.LocationInformation.MethodName;

                    //    if (loggingEventDto.LocationInformation.StackFrames != null)
                    //    {
                    //        // TODO: handle the entire tree of stack frames (may prove to be costly DB-wise)
                    //    }
                    //}
                }
                catch (Exception)
                {
                    // ignored
                }

                #endregion
            }
            catch (Exception ex)
            {
                myLog.ExceptionMessage += $"		====>		Exception saving exception: [ {ex.Message} ]";

                // Log to file...
                Log4NetLoggingFactory.GetLogger().LogWarning(null, myLog.ExceptionMessage, ex);
            }


            return(myLog);
        }