Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Serialize parameters with Nlog?

$
0
0

Im testing out the new structured logging but do not really get it right.

I have this in my nlog.config :

<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"><layout xsi:type="JsonLayout" includeAllProperties="true">${longdate}|${level}|${logger}|${message}</layout></target><logger name="CommunicationLogger" minlevel="Info" writeto="f"></logger>

My log code looks like this :

public void LogCommunication(string operation, List<object> args)    {        var parameters = new List<object>();        var text = "Operation:{Operation} ";        parameters.Add(operation);        text += "PersonId:{PersonId} ";        parameters.Add(SharedContext.GetMyUserContext().CurrentPersonId);        text += "ClientMachineName:{ComputerName} ";        parameters.Add(SharedContext.GetMyUserContext().ClientMachineName);        text += "Servername:{MachineName} ";        parameters.Add(Environment.MachineName);        if (args != null)        {            foreach(var param in args)            {                text += "Param:{@Parameters} ";                parameters.Add(param);            }        }        _log.LogCommunication(text, parameters.ToArray());    }public void LogCommunication(string message, params object[] args)        {            _comLogger.Log(LogLevel.Info, message, args);        }

The output looks something like this :

{ "Operation": "OperationName", "PersonId": 1, "ComputerName":"MyComputername", "MachineName": "MyMachinename", "Parameters": {"LocationKeyList":[], "MyObjectIdList":[], "RolList":[]} }

I would like the Parameters to also get serialize instead of just showint [] so I can see all the parameters of the service operation. The parameter is a complex type with dataContract(WCF).

Is there a simple way to get the parameters to work with structural data.

Retagards


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>