public static void Print(this DocumentClientException dex, Microsoft.Azure.WebJobs.Host.TraceWriter log) { if ((int)dex.StatusCode == 429) { log?.Info("TooManyRequests - This means you have exceeded the number of request units per second. Consult the DocumentClientException.RetryAfter value to see how long you should wait before retrying this operation."); } else { switch (dex.StatusCode) { case HttpStatusCode.BadRequest: log?.Info("BadRequest - This means something was wrong with the document supplied. It is likely that disableAutomaticIdGeneration was true and an id was not supplied"); break; case HttpStatusCode.Forbidden: log?.Info("Forbidden - This likely means the collection in to which you were trying to create the document is full."); break; case HttpStatusCode.Conflict: log?.Info("Conflict - This means a Document with an id matching the id field of document already existed"); break; case HttpStatusCode.RequestEntityTooLarge: log?.Info("RequestEntityTooLarge - This means the Document exceeds the current max entity size. Consult documentation for limits and quotas."); break; default: break; } } }
/// <summary> /// Adds a sink that writes log events to a <see cref="Microsoft.Azure.WebJobs.Host.TraceWriter"/>. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="trace">The trace writer instance to write to <see cref="LogEvent"/>s.</param> /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to /// the sink.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> public static LoggerConfiguration TraceWriter( this LoggerSinkConfiguration loggerConfiguration, Microsoft.Azure.WebJobs.Host.TraceWriter trace, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, IFormatProvider formatProvider = null) { if (loggerConfiguration == null) { throw new ArgumentNullException(nameof(loggerConfiguration)); } if (trace == null) { throw new ArgumentNullException(nameof(trace)); } return(loggerConfiguration.Sink(new TraceWriterSink(trace, formatProvider), restrictedToMinimumLevel)); }
/// <summary> /// Sample usage /// </summary> static void Main(string[] args) { // var loggerEnvironment = "AzureFunctions"; var loggerEnvironment = "ConsoleApp"; ILogger logger = null; if (loggerEnvironment == "AzureFunctions") { Microsoft.Azure.WebJobs.Host.TraceWriter azureFunctionLogger = null; logger = new AzureFunctionLogger(azureFunctionLogger); } else if (loggerEnvironment == "ConsoleApp") { logger = new TraceLogger(); } var doStuff = new DoStuff(logger); Console.ReadKey(); }
public AzureFunctionLogger(Microsoft.Azure.WebJobs.Host.TraceWriter logger) { _logger = logger; }