Example #1
0
        public void Emit(LogEvent logEvent)
        {
            var    property = logEvent.Properties.SingleOrDefault(p => p.Key == "SourceContext");
            var    source   = property.Value.ToString().RemoveQuotes();
            string commandText;

            if (logEvent.MessageTemplate.Text.Contains("An error occurred using a transaction."))
            {
            }
            else if (logEvent.MessageTemplate.Text.StartsWith("Executed DbCommand"))
            {
                commandText = logEvent.Properties.Single(p => p.Key == "commandText").Value.ToString();
            }

            if (traceLogEventSinkConfigArgs != null)
            {
                if (this.traceLogEventSinkConfigArgs.IncludeOnlySources != null && !this.traceLogEventSinkConfigArgs.IncludeOnlySources.Contains(source))
                {
                    return;
                }
                else if (this.traceLogEventSinkConfigArgs.ExcludeSources != null && this.traceLogEventSinkConfigArgs.ExcludeSources.Contains(source))
                {
                    return;
                }
            }

            using (this.Lock())
            {
                queuedEvents.Add(logEvent, logEvent);
            }
        }
Example #2
0
        public void Emit(LogEvent logEvent)
        {
            var    property    = logEvent.Properties.SingleOrDefault(p => p.Key == "SourceContext");
            var    source      = property.Value.ToString().RemoveQuotes();
            var    buffer      = new StringWriter(new StringBuilder(256));
            var    logFileName = loggerRelay.LogFileName;
            string commandText;
            string logMessage;

            formatter.Format(logEvent, buffer);
            logMessage = buffer.ToString();

            if (logEvent.MessageTemplate.Text.Contains("An error occurred using a transaction."))
            {
            }
            else if (logEvent.MessageTemplate.Text.StartsWith("Executed DbCommand"))
            {
                commandText = logEvent.Properties.Single(p => p.Key == "commandText").Value.ToString();
            }

            if (loggerRelayEventSinkConfigArgs != null)
            {
                if (!loggerRelayEventSinkConfigArgs.Enabled)
                {
                    return;
                }
                else if (this.loggerRelayEventSinkConfigArgs.IncludeOnlySources != null && !this.loggerRelayEventSinkConfigArgs.IncludeOnlySources.Contains(source))
                {
                    return;
                }
                else if (this.loggerRelayEventSinkConfigArgs.ExcludeSources != null && this.loggerRelayEventSinkConfigArgs.ExcludeSources.Contains(source))
                {
                    return;
                }
            }

            if (logFileName != null)
            {
                var success           = false;
                var x                 = 0;
                var captureAssemblies = captureStack[Path.GetFileNameWithoutExtension(logFileName)];

                if (captureAssemblies.InCaptureStack())
                {
                    while (!success)
                    {
                        try
                        {
                            var fileInfo = new FileInfo(logFileName);

                            if (!fileInfo.Directory.Exists)
                            {
                                fileInfo.Directory.Create();
                            }

                            WriteToLog(logMessage, logFileName);
                            success = true;
                        }
                        catch
                        {
                            if (x == 3)
                            {
                                using (this.Lock())
                                {
                                    queuedEvents.Add(new LoggerRelayEvent(logEvent, logFileName), logEvent);
                                }

                                break;
                            }

                            Thread.Sleep(1);
                            x++;
                        }
                    }
                }
            }
        }