/// <summary> /// Construct a sink posting to the specified Slack Channel. /// </summary> /// <param name="channels">Slack Channel list.</param> /// <param name="renderMessageImplementation">Optional delegate to build json to send to slack webhook. By default uses <see cref="RenderMessage"/>.</param> /// <param name="formatProvider">FormatProvider to apply to <see cref="LogEvent.RenderMessage(IFormatProvider)"/>.</param> /// <param name="username">Optional bot name</param> /// <param name="iconUrl">Optional URL to an image to use as the icon for this message.</param> public SlackSink(SlackChannelCollection channels, SlackSink.RenderMessageMethod renderMessageImplementation, IFormatProvider formatProvider, string username = null, string iconUrl = null) { if (channels == null) { throw new ArgumentNullException("channels"); } FormatProvider = formatProvider; Channels = channels; RenderMessageImplementation = renderMessageImplementation ?? RenderMessage; _username = username; _iconUrl = iconUrl; if (Channels.Count == 0) { SelfLog.WriteLine("There are 0 Slack channels defined. Slack sink will not send messages."); } }
/// <summary> /// Adds a sink that writes log events to a channel in Slack. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="channels">List of Slack channels.</param> /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="formatProvider">FormatProvider to apply in <see cref="LogEvent.RenderMessage(IFormatProvider)"/>. It overrides default behaviour.</param> /// <param name="username">Optional bot name</param> /// <param name="iconUrl">Optional URL to an image to use as the icon for this message.</param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> public static LoggerConfiguration VerboseSlack( this LoggerSinkConfiguration loggerConfiguration, SlackChannelCollection channels, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, IFormatProvider formatProvider = null, string username = null, string iconUrl = null ) { if (loggerConfiguration == null) { throw new ArgumentNullException(nameof(loggerConfiguration)); } if (channels == null) { throw new ArgumentNullException(nameof(channels)); } if (channels.Count == 0) { throw new ArgumentException("Must have at least one Slack channel defined."); } return (loggerConfiguration .Sink ( new SlackSink ( channels, new SlackVerboseRenderer(formatProvider).Render, formatProvider, username, iconUrl ), restrictedToMinimumLevel )); }