Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console Target Automatic Detect if console is available on Mono #1706

Merged
merged 1 commit into from
Oct 13, 2016

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Oct 12, 2016

Extended the console detection check to support Mono, that doesn't support Environment.UserInteractive. Attempt to fix #1704 (Not tested)


This change is Reviewable

@snakefoot snakefoot changed the title Console Target Automatic Detect if console is available on Mono #1704 Console Target Automatic Detect if console is available on Mono Oct 12, 2016
@snakefoot
Copy link
Contributor Author

snakefoot commented Oct 12, 2016

Strange that this build error has started to come "randomly":

...NLog.UnitTests.Targets.WrappedFileTargetTests.DeleteArchiveFilesByDateWithDateName [FAIL]
System.IO.IOException : The process cannot access the file 'C:\Users\appveyor\AppData\Local\Temp\1\38d53f98-4243-431f-921b-13c219a6989c\20161012182959914.txt' because it is being used by another process.
Stack Trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.Open(String path, FileMode mode)
C:\projects\nlog\src\NLog\Targets\FileTarget.cs(1307,0): at NLog.Targets.FileTarget.ArchiveFile(String fileName, String archiveFileName)
C:\projects\nlog\src\NLog\Targets\FileTarget.cs(1579,0): at NLog.Targets.FileTarget.ArchiveByDate(String fileName, String pattern, LogEventInfo logEvent)
C:\projects\nlog\src\NLog\Targets\FileTarget.cs(1764,0): at NLog.Targets.FileTarget.DoAutoArchive(String fileName, LogEventInfo eventInfo)
C:\projects\nlog\src\NLog\Targets\FileTarget.cs(1848,0): at NLog.Targets.FileTarget.TryArchiveFile(String fileName, LogEventInfo ev, Int32 upcomingWriteSize)
C:\projects\nlog\src\NLog\Targets\FileTarget.cs(1043,0): at NLog.Targets.FileTarget.ProcessLogEvent(LogEventInfo logEvent, String fileName, Byte[] bytesToWrite)
C:\projects\nlog\src\NLog\Targets\FileTarget.cs(1136,0): at NLog.Targets.FileTarget.FlushCurrentFileWrites(String currentFileName, LogEventInfo firstLogEvent, MemoryStream ms, List`1 pendingContinuations)
C:\projects\nlog\src\NLog\Targets\FileTarget.cs(1031,0): at NLog.Targets.FileTarget.Write(AsyncLogEventInfo[] logEvents)
C:\projects\nlog\src\NLog\Targets\Target.cs(287,0): at NLog.Targets.Target.WriteAsyncLogEvents(AsyncLogEventInfo[] logEvents)
C:\projects\nlog\tests\NLog.UnitTests\Targets\Mocks\MockTargetWrapper.cs(67,0): at NLog.UnitTests.Targets.Mocks.MockTargetWrapper.Write(AsyncLogEventInfo logEvent)
C:\projects\nlog\src\NLog\Targets\Target.cs(231,0): at NLog.Targets.Target.WriteAsyncLogEvent(AsyncLogEventInfo logEvent)
C:\projects\nlog\src\NLog\LoggerImpl.cs(252,0): at NLog.LoggerImpl.WriteToTargetWithFilterChain(TargetWithFilterChain targetListHead, LogEventInfo logEvent, AsyncContinuation onException)
C:\projects\nlog\src\NLog\LoggerImpl.cs(99,0): at NLog.LoggerImpl.Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)
C:\projects\nlog\src\NLog\Logger.cs(559,0): at NLog.Logger.WriteToTargets(LogLevel level, IFormatProvider formatProvider, String message)
C:\projects\nlog\src\NLog\Logger1.cs(454,0): at NLog.Logger.Debug(String message)
C:\projects\nlog\tests\NLog.UnitTests\Targets\FileTargetTests.cs(890,0): at NLog.UnitTests.Targets.FileTargetTests.DeleteArchiveFilesByDateWithDateName()

#if !SILVERLIGHT && !__IOS__ && !__ANDROID__ && !MONO
try
{
if (!Environment.UserInteractive)
{
if (Type.GetType("Mono.Runtime") != null && Console.In is StreamReader)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add this to PlatformDetector and create a unit test for it? (we run on Travis which is Mono)

@304NotModified
Copy link
Member

304NotModified commented Oct 12, 2016

Strange that this build error has started to come "randomly":

Guess I broke it then in 4.3.10 in #1680 :(

Any idea how to fix this? Guess we need a timer and a check if it's used.

@codecov-io
Copy link

Current coverage is 80% (diff: 50%)

Merging #1706 into master will increase coverage by <1%

@@             master      #1706   diff @@
==========================================
  Files           274        274          
  Lines         17031      17034     +3   
  Methods        2691       2692     +1   
  Messages          0          0          
  Branches       1904       1905     +1   
==========================================
+ Hits          13664      13667     +3   
- Misses         2930       2931     +1   
+ Partials        437        436     -1   

Sunburst

Powered by Codecov. Last update 2daa127...65d0d99

#if !SILVERLIGHT && !__IOS__ && !__ANDROID__ && !MONO
try
{
if (!Environment.UserInteractive)
{
if (Internal.PlatformDetector.IsMono && Console.In is StreamReader)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ps

I found a way to figure out whether there is a console/terminal available or not under mono on linux: 'Mono.Unix.Native.Syscall.isatty(0)'.

http://stackoverflow.com/questions/9065065/how-to-detect-if-im-running-in-mono-service

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

@304NotModified 304NotModified added this to the 4.3.11 milestone Oct 13, 2016
@304NotModified 304NotModified added the enhancement Improvement on existing feature label Oct 13, 2016
@304NotModified 304NotModified merged commit 90f0373 into NLog:master Oct 13, 2016
@snakefoot snakefoot deleted the InternalLoggerTrace branch October 13, 2016 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console-target enhancement Improvement on existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants