Exemplo n.º 1
0
        protected override void InitializeTarget()
        {
            StackifyLib.Utils.StackifyAPILogger.Log("NLog InitializeTarget");

            _logClient = new LogClient("StackifyLib.net-nlog", apiKey, uri);

#pragma warning disable CS0618 // Type or member is obsolete
            if (logAllProperties == false)
#pragma warning restore CS0618 // Type or member is obsolete
            {
                IncludeEventProperties = false;
            }

            if (logMethodNames == true)
            {
                IncludeCallSite = true;
            }

            if (ContextProperties.Count == 0)
            {
                ContextProperties.Add(new TargetPropertyWithContext()
                {
                    Name = "ndc", Layout = "${ndc:topFrames=1}"
                });

#pragma warning disable CS0618 // Type or member is obsolete
                var globalContextKeyList = globalContextKeys?.Split(',').Select(s => s.Trim()) ?? Enumerable.Empty <string>();

                foreach (var gdcKey in globalContextKeyList)
                {
                    if (string.IsNullOrEmpty(gdcKey))
                    {
                        continue;
                    }
                    ContextProperties.Add(new TargetPropertyWithContext()
                    {
                        Name = gdcKey, Layout = $"${{gdc:item={gdcKey}}}"
                    });
                }

                var mappedContextKeyList = mappedContextKeys?.Split(',').Select(s => s.Trim()) ?? Enumerable.Empty <string>();
                foreach (var mdcKey in mappedContextKeyList)
                {
                    if (string.IsNullOrEmpty(mdcKey))
                    {
                        continue;
                    }
                    ContextProperties.Add(new TargetPropertyWithContext()
                    {
                        Name = mdcKey, Layout = $"${{mdc:item={mdcKey}}}"
                    });
                }

                if (!String.IsNullOrEmpty(callContextKeys))
                {
                    _CallContextKeys = callContextKeys.Split(',').Select(s => s.Trim()).ToList();
                }
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
Exemplo n.º 2
0
        protected override void InitializeTarget()
        {
            if (ContextProperties.Count == 0)
            {
                ContextProperties.Add(new TargetPropertyWithContext(Constants.MachineName, "${MachineName}"));
                ContextProperties.Add(new TargetPropertyWithContext(Constants.ProcessName, "${ProcessName}"));
                ContextProperties.Add(new TargetPropertyWithContext(Constants.UserName, "${Environment-User}"));
                ContextProperties.Add(new TargetPropertyWithContext(Constants.Source, "${logger}"));
                ContextProperties.Add(new TargetPropertyWithContext(Constants.ThreadId, "${ThreadId}"));
            }

            base.InitializeTarget();

            var address = RenderLogEvent(Address, LogEventInfo.CreateNullEvent());

            _producer = new LogServer.Clients.AnalogyMessageProducer(address);
        }
        public void EnsureNestedPropertiesWork( )
        {
            string key = "some property";

            var outerProperty = new ContextProperties( );

            outerProperty.Add(key, "original");
            Assert.AreSame("original", outerProperty.Find(key), "Check set get");

            ContextProperties innerProperty = outerProperty.CreateChildContext( );

            Assert.AreSame("original", innerProperty.Find(key), "Check set at parent get at child");

            innerProperty.Add(key, "childValue");
            Assert.AreSame("childValue", innerProperty.Find(key), "Check set at child overrides parent");
            Assert.AreNotSame("childValue", outerProperty.Find(key), "Check setting at child does not override parent");
        }