public static LoggerConfiguration AzureLogAnalytics( this LoggerSinkConfiguration loggerConfiguration, string workspaceId, string primaryAuthenticationKey, string logName = "DiagnosticsLog", LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, bool storeTimestampInUtc = true, IFormatProvider formatProvider = null, int logBufferSize = 2000, int batchSize = 100, AzureOfferingType azureOfferingType = AzureOfferingType.Public) { if (string.IsNullOrEmpty(workspaceId)) { throw new ArgumentNullException(nameof(workspaceId)); } if (string.IsNullOrEmpty(primaryAuthenticationKey)) { throw new ArgumentNullException(nameof(primaryAuthenticationKey)); } return(loggerConfiguration.Sink( new AzureLogAnalyticsSink( workspaceId, primaryAuthenticationKey, null, logName, storeTimestampInUtc, formatProvider, logBufferSize, batchSize, azureOfferingType), restrictedToMinimumLevel)); }
/// <summary> /// Adds a sink that writes log events to a Azure Log Analytics. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="workspaceId">Workspace Id from Azure OMS Portal connected sources.</param> /// <param name="authenticationId"> /// Primary or Secondary key from Azure OMS Portal connected sources. /// </param> /// <param name="logName">A distinguishable log type name. Default is "DiagnosticsLog"</param> /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="storeTimestampInUtc">Flag dictating if timestamp to be stored in UTC or local timezone format.</param> /// <param name="formatProvider"> /// Supplies an object that provides formatting information for formatting and parsing /// operations /// </param> /// <param name="logBufferSize">Maximum number of log entries this sink can hold before stop accepting log messages. Supported size is between 5000 and 25000</param> /// <param name="batchSize">Number of log messages to be sent as batch. Supported range is between 1 and 1000</param> /// <param name="azureOfferingType">Azure offering type for public or government. Default is AzureOfferingType.Public</param> /// <param name="levelSwitch"> /// A switch allowing the pass-through minimum level to be changed at runtime. /// </param> /// <param name="flattenObject">Flat out complex object into simple object. All nested properties will move to root level with computed names</param> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> public static LoggerConfiguration AzureAnalytics( this LoggerSinkConfiguration loggerConfiguration, string workspaceId, string authenticationId, string logName = "DiagnosticsLog", LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, bool storeTimestampInUtc = true, IFormatProvider formatProvider = null, int logBufferSize = 2000, int batchSize = 100, AzureOfferingType azureOfferingType = AzureOfferingType.Public, LoggingLevelSwitch levelSwitch = null, bool flattenObject = true) { if (string.IsNullOrEmpty(workspaceId)) { throw new ArgumentNullException(nameof(workspaceId)); } if (string.IsNullOrEmpty(authenticationId)) { throw new ArgumentNullException(nameof(authenticationId)); } return(loggerConfiguration.Sink( new AzureLogAnalyticsSink( workspaceId, authenticationId, logName, storeTimestampInUtc, formatProvider, logBufferSize, batchSize, azureOfferingType, flattenObject), restrictedToMinimumLevel, levelSwitch)); }
private static Uri GetServiceEndpoint(AzureOfferingType azureOfferingType, string workspaceId) { string offeringDomain; switch (azureOfferingType) { case AzureOfferingType.Public: offeringDomain = "azure.com"; break; case AzureOfferingType.US_Government: offeringDomain = "azure.us"; break; case AzureOfferingType.China: offeringDomain = "azure.cn"; break; default: throw new ArgumentOutOfRangeException(); } return(new Uri( $"https://{workspaceId}.ods.opinsights.{offeringDomain}/api/logs?api-version=2016-04-01")); }