Skip to content

Quick Azure How To

cdmdotnet edited this page Nov 25, 2019 · 2 revisions

Start by following the Basic Quick How To then modify you configuration as follows.

Program.cs

static void Main()
{
  ICorrelationIdHelper correlationIdHelper = new WebCorrelationIdHelper();
  // This value will be set automatically to all logs within this thread... so long as System.Threading.Tasks.Task.Factory.StartNew is used.
  correlationIdHelper.SetCorrelationId(Guid.NewGuid());
  DoSyncWork();
  DoAsyncWork();
}

static void DoSyncWork()
{
  ILogger logger = new SqlLogger();
  logger.LogDebug("Some technical debugging details.");
  // This WILL NOT get logged due to the settings below
  logger.LogProgress("Some progress details.");
}

static void DoAsyncWork()
{
  System.Threading.Tasks.Task.Factory.StartNew(() => {
    ILogger logger = new ConsoleLogger();
    logger.LogInfo("An informative message.", "Sync Work");
    // This WILL get logged due to the settings below
    logger.LogProgress("Some progress details.");
  });
}

For the .NET Framework, add the following to your app.config

<appSettings>
	<add key="EnableLogInfo" value="true"  />
	<add key="EnableLogProgress" value="false"  />
	<add key="EnableLogSensitive" value="false"  />
	<add key="EnableLogDebug" value="false"  />
	<add key="EnableLogWarning" value="true"  />
	<add key="EnableLogError" value="true"  />
	<add key="EnableLogFatalError" value="true"  />
	<add key="EnableLogThreadedLogging" value="true"  />
	<add key="ModuleName" value="MyCompany"  />
	<add key="Instance" value="MyApplication"  />
	<add key="EnvironmentInstance" value="Server1"  />
	<add key="Environment" value="Production"  />
	<add key="EnableThreadedLoggingOutput" value="true"  />
	<add key="UseApplicationInsightTelemetryHelper" value="false"  />
	<add key="SqlDatabaseLogsConnectionStringName" value="SqlDatabaseLogs.Local"  />
	<add key="SqlDatabaseTableName" value="Logs" />
	<!-- Different logger settings for my special function -->
	<add key="EnableLogProgress.DoAsyncWork" value="true"  />
</appSettings>

	<connectionStrings>
		<add name="SqlDatabaseLogs.Local" connectionString="Initial Catalog=DevelopmentLog;Data Source=localhost;Trusted_Connection=True;Connection Timeout=30;MultipleActiveResultSets=False; Enlist=False;" providerName="System.Data.SqlClient" />
		<add name="SqlDatabaseLogs.Production" connectionString="Initial Catalog=ProductLogs;Data Source=localhost;Trusted_Connection=True;Connection Timeout=30;MultipleActiveResultSets=False; Enlist=False;" providerName="System.Data.SqlClient" />
	</connectionStrings>

For the .NET Core, add the following to your settings.json

{
	... other settings
	"Chinchilla": {
		"Logging": {
			"EnableLogInfo": true,
			"EnableLogProgress": false,
			"EnableLogSensitive": false,
			"EnableLogDebug": false,
			"EnableLogWarning": true,
			"EnableLogError": true,
			"EnableLogFatalError": true,
			"EnableLogThreadedLogging": true,
			"ModuleName": "MyCompany",
			"Instance": "MyApplication",
			"EnvironmentInstance": "Server1",
			"Environment": "Production",
			"EnableThreadedLoggingOutput": true,
			"UseApplicationInsightTelemetryHelper": false,
			"SqlDatabaseLogsConnectionStringName": "SqlDatabaseLogs.Local",
			"SqlDatabaseTableName": "Logs",
			// Different logger settings for my special function
			"DoAsyncWork": {
				// Above the setting is false, here I set it to true for just this function
				"EnableLogProgress": true
			}
		}
	}
}
Clone this wiki locally