Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogData"/> class.
        /// </summary>
        /// <param name="timeStamp">The time stamp.</param>
        /// <param name="eventId">The event identifier.</param>
        /// <param name="correlationId">The correlation identifier.</param>
        /// <param name="level">The level.</param>
        /// <param name="message">The message.</param>
        /// <param name="username">The username.</param>
        /// <param name="machineName">Name of the machine.</param>
        /// <param name="processId">The process identifier.</param>
        /// <param name="processName">Name of the process.</param>
        /// <param name="appDomainName">Name of the application domain.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="logLocation">The log location.</param>
        /// <param name="properties">The properties.</param>
        /// <exception cref="System.ArgumentNullException">correlationId</exception>
        public LogData(
            DateTime timeStamp,
            Guid eventId,
            Option <Guid> correlationId,
            Level level,
            string message,
            string username,
            string machineName,
            int processId,
            string processName,
            string appDomainName,
            Exception exception,
            LogLocation logLocation,
            Dictionary <string, object> properties)
        {
            if (correlationId == null)
            {
                throw new ArgumentNullException("correlationId");
            }

            TimeStamp       = timeStamp;
            EventId         = eventId;
            CorrelationId   = correlationId;
            Level           = level;
            Message         = message;
            LogLocation     = logLocation;
            Username        = username;
            MachineName     = machineName;
            ProcessId       = processId;
            ProcessIdString = processId.ToString(CultureInfo.InvariantCulture);
            ProcessName     = processName;
            AppDomainName   = appDomainName;
            Exception       = exception;
            Properties      = properties;
        }
        private Guid LogEntry(
            TLoggerImplementation activeLogger,
            LogLocation logLocation,
            Guid?explicitCorrelationId,
            Exception exception,
            Level level,
            object extendedProperties,
            string message)
        {
            try
            {
                var eventId = Guid.NewGuid();
                var extendedPropertyValues =
                    CalculateExtendedProperties(extendedProperties, out var extendedCorrelationId);

                var username = ThreadPrincipal.Resolve(DiagnosticsEnabled);

                var actualCorrelationId = CalculateCorrelationId(
                    explicitCorrelationId,
                    extendedCorrelationId);

                var logData = new LogData(
                    TimeProvider.UtcNow,
                    eventId,
                    actualCorrelationId,
                    level,
                    message,
                    username,
                    MachineName,
                    currentProcess.Id,
                    currentProcessName,
                    currentAppDomainName,
                    exception,
                    logLocation,
                    extendedPropertyValues);

                PerformLogEntry(activeLogger, logData);
                return(eventId);
            }
            catch (Exception ex)
            {
                if (DiagnosticsEnabled)
                {
                    Trace.WriteLine(ex.ToString());
                }

                return(Guid.Empty);
            }
        }
 /// <summary>
 /// Gets the implementation of the individual logging framework's logger.
 /// </summary>
 /// <param name="logLocation">The log location.</param>
 /// <returns>TLoggerImplementation.</returns>
 protected override NullLogWrapper PerformGetLogger(LogLocation logLocation)
 {
     return(this);
 }
 /// <summary>
 /// Gets the implementation of the individual logging framework's logger.
 /// </summary>
 /// <param name="logLocation">The log location.</param>
 /// <returns>TLoggerImplementation.</returns>
 protected abstract TLoggerImplementation PerformGetLogger(LogLocation logLocation);