Reputation: 85
I've two separate tables to log user activity and errors in asp.net web Api.
Here's my Activity Log table:
To store the Log information in the table, Here's the Nlog.config setting.
<target name="database" xsi:type="Database" keepConnection="true" useTransactions="true"
dbProvider="System.Data.SqlClient" commandType="Text"
connectionString="data source=XXXXX;initial catalog=XXXXX;integrated security=false;persist security info=True;User ID=XXXXX;Password=XXXXX"
commandText="INSERT INTO [dbo].[ActivityLog]([PageName],[MethodName],[IPAddress],[RequestedUrl],[IsAuthenticated],[UserName],[Date]) VALUES(@PageName,@MethodName,@IPAddress,@RequestedUrl,@IsAuthenticated,@UserName,@Date)">
<parameter name="@PageName" layout="" />
<parameter name="@MethodName" layout="" />
<parameter name="@IPAddress" layout=""/>
<parameter name="@RequestedUrl" layout="${aspnet-request:serverVariable=HTTP_URL}"/>
<parameter name="@IsAuthenticated" layout="${aspnet-user-identity}:isAuthenticated"/>
<parameter name="@UserName" layout="${aspnet-user-identity}"/>
<parameter name="@Date" layout="${date:s}"/>
</target>
For the Page Name parameter I need the Web API Controller Name, and for Method Name parameter I need the action Method of the Controller that is called. Also I need to know whether the user is authenticated or not.
Now Kindly let me know the settings defined in the Nlog config file are correct or not and also how to pass values to the other parameters.
Upvotes: 1
Views: 2304
Reputation: 36830
All possible layout renderers could be found here. You could use the following renderers:
${aspnet-MVC-Controller}
${callsite}
or ${aspnet-mvc-action}
${identity:isAuthenticated}
PS:
Upvotes: 2